Codeforces Round #368 (Div. 2) 题解
来源:互联网 发布:天下x天下 人祸和知彼 编辑:程序博客网 时间:2024/06/16 20:27
- Brains Photos
- Bakery
- Pythagorean Triples
- Persistent Bookcase
- Garlands
Brain’s Photos
#include<bits/stdc++.h>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define ForkD(i,k,n) for(int i=n;i>=k;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=Pre[x];p;p=Next[p])#define Forpiter(x) for(int &p=iter[x];p;p=Next[p]) #define Lson (o<<1)#define Rson ((o<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (1000000007)#define pb push_back#define mp make_pair #define fi first#define se second#define vi vector<int> #define pi pair<int,int>#define SI(a) ((a).size())#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;#define PRi2D(a,n,m) For(i,n) { \ For(j,m-1) cout<<a[i][j]<<' ';\ cout<<a[i][m]<<endl; \ } #pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef long double ld;typedef unsigned long long ull;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return ((a-b)%F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int read(){ int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();} while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();} return x*f;} int main(){// freopen("A.in","r",stdin);// freopen(".out","w",stdout); int n=read(),m=read(); For(i,n) For(j,m) { char c[2]; scanf("%s",c); if (c[0]=='C'||c[0]=='M'||c[0]=='Y') { puts("#Color"); return 0; } } puts("#Black&White"); return 0;}
Bakery
#include<bits/stdc++.h>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define ForkD(i,k,n) for(int i=n;i>=k;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=Pre[x];p;p=Next[p])#define Forpiter(x) for(int &p=iter[x];p;p=Next[p]) #define Lson (o<<1)#define Rson ((o<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (1000000007)#define pb push_back#define mp make_pair #define fi first#define se second#define vi vector<int> #define pi pair<int,int>#define SI(a) ((a).size())#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;#define PRi2D(a,n,m) For(i,n) { \ For(j,m-1) cout<<a[i][j]<<' ';\ cout<<a[i][m]<<endl; \ } #pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef long double ld;typedef unsigned long long ull;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return ((a-b)%F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int read(){ int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();} while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();} return x*f;} struct Edge{ int from,to; ll dist;};struct HeapNode { ll d; int u; bool operator< (const HeapNode& rhs) const { return d > rhs.d; }}; #define MAXN (101000)struct Dijkstra { int n,m; vector<Edge> edges; vector<int> G[MAXN]; bool done[MAXN]; ll d[MAXN]; int p[MAXN]; //×î¶Ì·ÖÐÉÏÒ»Ìõ±ß int pnode[MAXN]; void addedge(int u,int v,ll w){ edges.pb((Edge){u,v,w}); G[u].pb(m++); } void addedge2(int u,int v,ll w) { addedge(u,v,w);addedge(v,u,w); } void init(int _n){ n=_n; m = 0; Rep(i,n) G[i].clear(); edges.clear(); } void dijkstra(int k) { priority_queue<HeapNode> Q; Rep(i,n) d[i]=(ll)1e14,pnode[i]=-1; MEM(done) Rep(i,k) { int p=read(); d[p]=0; Q.push((HeapNode){0,p}); } while(!Q.empty()) { HeapNode x=Q.top(); Q.pop(); int u=x.u; if (done[u]) continue; done[u]=1; int mm=G[u].size(); Rep(i,mm) { Edge e = edges[G[u][i]]; if (d[e.to]>d[u]+e.dist) { d[e.to]=d[u]+e.dist; p[e.to]=G[u][i]; pnode[e.to]=u; Q.push((HeapNode){d[e.to],e.to}); } } } ll p=(ll)1e14; Rep(i,n) if (d[i]!=(ll)1e14&&d[i]>0) { p=min(p,d[i]) ; } if (p==(ll)1e14) puts("-1"); else cout<<p<<endl; } }S1;int main(){// freopen("B.in","r",stdin);// freopen(".out","w",stdout); int n=read(),m=read(),k=read(); S1.init(1+n); Rep(i,m){ int u=read(),v=read(),w=read(); S1.addedge2(u,v,w); } if (k==n||k==0) { puts("-1"); return 0; } S1.dijkstra(k); return 0;}
Pythagorean Triples
公式:
#include<bits/stdc++.h>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define ForkD(i,k,n) for(int i=n;i>=k;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=Pre[x];p;p=Next[p])#define Forpiter(x) for(int &p=iter[x];p;p=Next[p]) #define Lson (o<<1)#define Rson ((o<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (1000000007)#define pb push_back#define mp make_pair #define fi first#define se second#define vi vector<int> #define pi pair<int,int>#define SI(a) ((a).size())#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;#define PRi2D(a,n,m) For(i,n) { \ For(j,m-1) cout<<a[i][j]<<' ';\ cout<<a[i][m]<<endl; \ } #pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef long double ld;typedef unsigned long long ull;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return ((a-b)%F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int read(){ int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();} while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();} return x*f;} ll m,k;ll calc(ll &m,ll &k,ll n) { if (n%2) { ll t=(n-1)/2; m=t*t; k=(t+1)*(t+1); } else { calc(m,k,n/2); m*=2;k*=2; }}int main(){// freopen("C.in","r",stdin);// freopen(".out","w",stdout); ll n=read(); if (n<=2) puts("-1"); else if (n%2==1) { n=n*n; n=(n-1)/2; cout<<n<<' '<<n+1<<endl; return 0; } else { n/=2; ll t=1,q=n; cout<<q*q-t*t<<' '<<q*q+t*t<<endl; return 0; } return 0;}
Persistent Bookcase
只需要转移列,和每行对应的列
#include<bits/stdc++.h>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define ForkD(i,k,n) for(int i=n;i>=k;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=Pre[x];p;p=Next[p])#define Forpiter(x) for(int &p=iter[x];p;p=Next[p]) #define Lson (o<<1)#define Rson ((o<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (1000000007)#define pb push_back#define mp make_pair #define fi first#define se second#define vi vector<int> #define pi pair<int,int>#define SI(a) ((a).size())#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;#define PRi2D(a,n,m) For(i,n) { \ For(j,m-1) cout<<a[i][j]<<' ';\ cout<<a[i][m]<<endl; \ } #pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef long double ld;typedef unsigned long long ull;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return ((a-b)%F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int read(){ int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();} while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();} return x*f;} #define MAXN (1000+10)#define MAXM (1000+10)#define MAXQ (100000+10)int last[MAXQ][MAXN]={},ans[MAXQ]={};bool rw[MAXQ][MAXM]={};int main(){// freopen("D.in","r",stdin);// freopen(".out","w",stdout); int n=read(),m=read(),q=read(); int k; For(i,q) { int op=read(); if (op==4) { k=read(); copy_n(last[k],n,last[i]); ans[i]=ans[k]; } else { copy_n(last[i-1],n,last[i]); ans[i]=ans[i-1]; if (op<=2) { int a=read(),b=read(); a--,b--; copy_n(rw[last[i][a]],m,rw[i]); last[i][a]=i; if (op==1&&rw[i][b]==0) ans[i]++,rw[i][b]=1; if (op==2&&rw[i][b]==1) ans[i]--,rw[i][b]=0; } else { int a=read(); a--; copy_n(rw[last[i][a]],m,rw[i]); last[i][a]=i; Rep(j,m) if (rw[i][j]) ans[i]--; else ans[i]++; Rep(j,m) rw[i][j]^=1; } } cout<<ans[i]<<endl; } return 0;}
Garlands
时限3秒,二维树状数组暴力修改过。
#include<bits/stdc++.h>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define ForkD(i,k,n) for(int i=n;i>=k;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=Pre[x];p;p=Next[p])#define Forpiter(x) for(int &p=iter[x];p;p=Next[p]) #define Lson (o<<1)#define Rson ((o<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (1000000007)#define pb push_back#define mp make_pair #define fi first#define se second#define vi vector<int> #define pi pair<int,int>#define SI(a) ((a).size())#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;#define PRi2D(a,n,m) For(i,n) { \ For(j,m-1) cout<<a[i][j]<<' ';\ cout<<a[i][m]<<endl; \ } #pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef long double ld;typedef unsigned long long ull;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return ((a-b)%F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int read(){ int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();} while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();} return x*f;} #define MAXN (2000+10)int a[MAXN][MAXN],n,m,k;vector<pi > col[MAXN];ll f[MAXN][MAXN]={0}; void add(int x,int y,ll v) {// cout<<x<<' '<<y<<' '<<v<<endl; for(int i=x;i<=n;i+=i&(-i)) for(int j=y;j<=m;j+=j&(-j)) f[i][j]+=v;}ll qur(int x,int y) { ll v=0; for(int i=x;i;i-=i&(-i)) for(int j=y;j;j-=j&(-j)) v+=f[i][j]; return v;}bool b[MAXN]={0},la[MAXN]={0};int main(){// freopen("E.in","r",stdin);// freopen(".out","w",stdout); n=read(),m=read(),k=read(); For(i,k) { int t=read(); Rep(j,t) { int u=read(),v=read(); a[u][v]=read(); col[i].pb(mp(u,v)); } la[i]=1; } int q=read(); while(q--) { string s; cin>>s; if (s[0]=='A') { For(i,k) if (la[i]^b[i]) { b[i]^=1; Rep(j,SI(col[i])) add(col[i][j].fi,col[i][j].se,(la[i]?1:-1)*a[col[i][j].fi][col[i][j].se]); } int x1=read(),y1=read(),x2=read(),y2=read(); cout<<qur(x2,y2)-qur(x1-1,y2)-qur(x2,y1-1)+qur(x1-1,y1-1)<<endl; } else { la[read()]^=1; } } return 0;}
0 0
- Codeforces Round #368 (Div. 2) 题解
- 【codeforces】Codeforces Round #276 (Div. 2) 题解
- 【codeforces】Codeforces Round #277 (Div. 2) 题解
- 【codeforces】Codeforces Round #279 (Div. 2) 题解
- 【codeforces】Codeforces Round #283 (Div. 2) 【题解】
- 【codeforces】Codeforces Round #291 (Div. 2) 题解
- Codeforces Round #131 (Div. 2) 完整题解
- Codeforces Round #135 (Div. 2)题解
- Codeforces Round #192 (Div. 2) 题解报告
- Codeforces Round #194 (Div. 2) 题解
- Codeforces Round #216 (Div. 2)部分题解
- Codeforces Round #226 (Div. 2) 题解
- Codeforces Round #177 (Div. 2) 题解
- Codeforces Round #FF (Div. 2) 题解
- Codeforces Round #256 (Div. 2) 题解
- Codeforces Round #257 (Div. 2) 题解
- Codeforces Round #259 (Div. 2) 题解
- Codeforces Round #260 (Div. 2) 题解
- 数据结构实验之查找五:平方之哈希表
- Sqrt Bo
- (2) freemarker入门案例2
- OpenCV提取显示一张图片(或者视频)的R,G,B颜色分量
- 网易搬家来,开始CSDN码字!!
- Codeforces Round #368 (Div. 2) 题解
- Android studio隐藏标题栏
- HDU 2122 Ice_cream’s world III
- Java程序员开发参考资源
- CodeForces 687A
- OSG 3.0 Beginners Guide DEC.2010
- Til the Cows Come Home
- 装饰者设计模式
- express redis socket 消息提醒方案:本地emit 轮循服务器获取redis 再推送