B:分析序列 构造树(优先队列)
#include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define foror(i,a,b) for(i=a;i<b;i++) #define foror2(i,a,b) for(i=a;i>b;i--) #define EPS 1.0e-8 #define PI acos(-1.0) #define INF 3000000000 #define MOD 1000000009 #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!! ") #define lson o<<1, l, m #define rson o<<1|1, m+1, r //using ll = long long; //using ull= unsigned long long; //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; typedef long long ll; vector<int> tree[8000]; int visit[8000]; int pop=0; int pop1=1; int scan[8000]; priority_queue<int, vector<int>, greater<int> > leaf; int maxn=0; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int now; //TS; while(scanf("%d ",&now)!=EOF) { scan[++pop]=now; maxn=max(maxn,now); visit[now]++; } //cout<<maxn<<endl; visit[maxn]++; //TS; for(int i=1;i<=maxn;i++) { if(visit[i]==0) { leaf.push(i); } } while(!leaf.empty()) { int cur; cur= leaf.top(); leaf.pop(); tree[scan[pop1]].push_back(cur); //cout<<scan[pop1]<<"pushin:"<<cur<<endl; tree[cur].push_back(scan[pop1]); //cout<<cur<<"pushin:"<<scan[pop1]<<endl; if(--visit[scan[pop1]]==0) leaf.push(scan[pop1]); pop1++; } for(int i=1;i<=maxn;i++) { //printf("%d ",tree[i].size()); sort(tree[i].begin(),tree[i].end()); printf("%d:",i); for(int j=0;j<(int)tree[i].size();j++) { printf(" %d",tree[i][j]); } printf(" "); } return 0; }
C:求满足题意的正方形个数(二维前缀和 前缀和思想) 更难的相似的:http://agc015.contest.atcoder.jp/tasks/agc015_c
F: 打表找规律
#include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define foror(i,a,b) for(i=a;i<b;i++) #define foror2(i,a,b) for(i=a;i>b;i--) #define EPS 1.0e-8 #define PI acos(-1.0) #define INF 3000000000 #define MOD 1000000009 #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!! ") #define lson o<<1, l, m #define rson o<<1|1, m+1, r //using ll = long long; //using ull= unsigned long long; //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; typedef long long ll; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int t; cin >> t; while(t--) { int s,k; scanf("%d %d",&s,&k); if(k%2==1) { if(s%2==0) { cout<<0<<endl; continue; } else { cout<<1<<endl; continue; } } else { /*int now=0; while(s>0) { now+=s%k; s/=k; } cout<<now<<endl;*/ int now=s%(k+1); if(now%2==1) cout<<1<<endl; else { if(now==k) cout<<k<<endl; else cout<<0<<endl; } } } return 0; }
G:水
H:二进制分析(lucky 测试数据没有失败的也没有要求最优解的)
#include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define foror(i,a,b) for(i=a;i<b;i++) #define foror2(i,a,b) for(i=a;i>b;i--) #define EPS 1.0e-8 #define PI acos(-1.0) #define INF 3000000000 #define MOD 1000000009 #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!! ") #define lson o<<1, l, m #define rson o<<1|1, m+1, r //using ll = long long; //using ull= unsigned long long; //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; typedef long long ll; int er[100]; int er2[100]; int ans[100]; ll l,r; int pop=0; ll anser1=0; void init(ll t) { int pop=0; while(t>0) { er[pop++]=t%2; t=t/2; } } void init2(ll t) { int pop=0; while(t>0) { er2[pop++]=t%2; t=t/2; } } ll now[100]; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); mem(ans,-1); int flag=1; int have=0; int n; cin >> n; for(int i=1;i<=n;i++) cin>>now[i]; for(int i=1;i<n;i++) { if(flag==0) break; mem(er,0); mem(er2,0); ll cur=now[i]; ll next=now[i+1]; init(cur); init2(next); int flag2=0; for(int j=59;j>=0;j--) { if(er[j]!=er2[j]) { // cout<< j<<endl; if(er[j]==0&&er2[j]==1) { if(ans[j]==-1) { ans[j]=0; have++; flag2=1; break; } else if(ans[j]==0) { flag2=1; break; } } else if(er[j]==1&&er2[j]==0) { if(ans[j]==-1) { ans[j]=1; have++; flag2=1; break; } else if(ans[j]==1) { flag2=1; break; } } } } if(flag2==0) flag=0; } if(flag==0) { cout<<0<<endl; return 0; } ll anser=1LL*1<<(60-have); cout<<anser<<endl; return 0; }
I:数位DP
#include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define foror(i,a,b) for(i=a;i<b;i++) #define foror2(i,a,b) for(i=a;i>b;i--) #define EPS 1.0e-8 #define PI acos(-1.0) #define INF 3000000000 #define MOD 1000000007 #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!! ") #define lson o<<1, l, m #define rson o<<1|1, m+1, r //using ll = long long; //using ull= unsigned long long; //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; typedef long long ll; ll ans[2005][4]; void init() { ans[1][1]=26,ans[1][2]=ans[1][3]=0; for(int i=1;i<=1999;i++) { ans[i+1][1]=(ans[i][1]+ans[i][2]+ans[i][3])*25%MOD; ans[i+1][2]=ans[i][1]%MOD,ans[i+1][3]=ans[i][2]%MOD; } } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); init(); int t; cin >> t; while(t--) { int n; scanf("%d",&n); ll anser=(ans[n][1]+ans[n][2]+ans[n][3])%MOD; cout<<anser<<endl; } return 0; }