今天第二次做BC,不习惯hdu的oj,CE过2次。。。
1002 Clarke and problem
#include<cstdio> #include<iostream> #include<string> #include<cstring> #include<queue> #include<vector> #include<stack> #include<vector> #include<map> #include<set> #include<algorithm> using namespace std; #define PB push_back #define MP make_pair #define fi first #define se second #define cer(x) cout<<#x<<‘=‘<<endl typedef long long ll; const int maxn = 1050; int dp[2][maxn]; //#define LOCAL const int MOD = 1e9+7; int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif int T; scanf("%d",&T); while(T--){ int n,p; scanf("%d%d",&n,&p); //fill(dp[0],dp[0]+p,0); memset(dp[0],0,sizeof(dp[0])); dp[0][0] = 1; for(int i = 0; i < n; i++){ int c = i&1,nx = (i&1)^1; //fill(dp[nx],dp[nx]+p,0); memcpy(dp[nx],dp[c],sizeof(dp[nx])); int a; scanf("%d",&a); a %= p; if(a<0) a += p; //G++编译器负数取模还是负数,在这里RE了几次 for(int j = 0; j < p; j++){ if(dp[c][j]){ int t = (j+a)%p; dp[nx][t] = (dp[nx][t]+ dp[c][j])%MOD; } } } printf("%d\n",dp[n&1][0]); } return 0; }
1003 Clarke and puzzle
卡时间卡的太紧了,按照官方题解做法980ms过。。。把memset换成for,890ms
自信地写了个二维线段树被卡。写BIT还遇到一些奇怪的错误。
#include<cstdio> #include<iostream> #include<string> #include<cstring> #include<queue> #include<vector> #include<stack> #include<vector> #include<map> #include<set> #include<algorithm> using namespace std; #define PB push_back #define MP make_pair #define fi first #define se second #define cer(x) cout<<#x<<‘=‘<<endl typedef long long ll; const int maxn = 505; int C[maxn][maxn],n,m,c[maxn][maxn]; #define lb(x) ((x)&-(x)) int sum(int x,int y){ int r = 0; for(int i=x;i>0;i-=lb(i)) //for(; x>0; x-=lb(x)) 奇怪的错误,写成这样T了 for(int j=y;j>0;j-=lb(j)) r ^= C[i][j]; return r; } void add(int x,int y,int val){ for(int i=x;i<=n;i+=lb(i)) for(int j=y;j<=m;j+=lb(j)) C[i][j] ^= val; } //#define LOCAL int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif int T; scanf("%d",&T); while(T--){ int q; scanf("%d%d%d",&n,&m,&q); //memset(C,0,sizeof(C)); for(int i = 1; i <= n; i++){ //fill(C[i]+1,C[i]+1+m,0); for(int j = 1; j <= m; j++) C[i][j] = 0; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ scanf("%d",c[i]+j); add(i,j,c[i][j]); } } for(int i = 0; i < q; i++){ int op; scanf("%d",&op); if(op == 1){ int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); puts(sum(x2,y2)^sum(x2,y1-1)^sum(x1-1,y2)^sum(x1-1,y1-1)?"Yes":"No"); }else { int x,y,v; scanf("%d%d%d",&x,&y,&v); add(x,y,c[x][y]^v); c[x][y] = v; } } } return 0; }
时间: 2024-12-19 23:53:49