签到题
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"------------"< se;
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
se.insert(a[i]);
}
set:: iterator it;
int i = 0;
bool flag = false;
for(it = se.begin(); it != se.end(); it++){
if(i != *it){
printf("%d\n", i);
flag = true;
break;
}
i++;
}
if(!flag) printf("%d\n", i);
}
return 0;
}
DP一下
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"------------"<=a [i])
dp[i][j] = (dp[i-1][j] + dp[i][j-a[i]]) % MOD;
}
}
printf("%lld\n", dp[15][n]);
}
return 0;
}
区间的nim博弈, 清空数组用多少清多少就没超时(卡过去的)。要把2^n预处理出来。
预处理 耗时770 , 没有预处理耗时984
预处理的代码:
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"------------"<
水题,从l的最低位向高位开始变化,遇到0变成1 判断是否小于r
#include
using namespace std;
typedef long long ll;
ll z[100];
int main(){
ll l, r;
scanf("%lld%lld", &l, &r);
ll k = l;
ll cnt = 0, num = 0;
while(k){
z[cnt] = k % 2;
k /= 2;
cnt++;
}
ll ans = l,w=1;
for(ll i = 0; i < 65; i++){
if(z[i] == 0){
ll sum = ans + ((ll)1<
bfs一遍标记
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"------------"< Q;
node u;
u.x = x; u.y = y; u.t = 0;
Q.push(u);
vis[x][y] = true;
while(!Q.empty()){
node top = Q.front();
Q.pop();
for(int i = 0; i < 4; i++){
int dx = top.x + dir[0][i];
int dy = top.y + dir[1][i];
if(dx>=1 && dx<=n && dy>=1 && dy<=m && top.t+1<=mp[dx][dy] && vis[dx][dy]==0){
node v;
v.x = dx; v.y = dy; v.t = top.t + 1;
mp[dx][dy] = v.t;
vis[dx][dy] = true;
Q.push(v);
}
}
}
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
mp[i][j] = INF;
scanf("%d", &x);
if(x == 1) mp[i][j] = 0;
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(mp[i][j] == 0){
bfs(i, j);
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j < m; j++){
printf("%d ", mp[i][j]);
}
printf("%d\n", mp[i][m]);
}
return 0;
}
/*
2 3
0 0 0
1 0 1
*/
签到题
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"------------"<
签到题
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"------------"<> n;
ll sum = 0, x;
for(int i = 0; i < n; i++){
scanf("%lld", &x);
sum += x;
}
if(sum > 0) printf("icebound is happy.\n" );
else if(sum == 0) printf("icebound is ok.\n");
else printf("icebound is sad.\n");
return 0;
}