Codeforces Round #268 (Div. 2) ABCD

CF469

Codeforces Round #268 (Div. 2)

http://codeforces.com/contest/469

开学了,时间少,水题就不写题解了,不水的题也不写这么详细了。

A

水题

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define mp make_pair
#define pb push_back bool a[]; int main(){
int n,m,i,x;
RD(n);
RD(m);
mz(a);
REP(i,m){RD(x);a[x]=;}
RD(m);
REP(i,m){RD(x);a[x]=;}
bool flag=;
FOR(i,,n){
if(a[i]==){flag=;break;}
}
if(flag)puts("I become the guy.");
else puts("Oh, my keyboard!");
return ;
}

B

模拟,狂撸

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define mp make_pair
#define pb push_back int a[],b[],c[],d[];
int p,q,l,r; bool gank(int x){
int i,j;
j=;
d[q]=;
REP(i,p){
while(d[j]+x<a[i])j++;
if(j>=q)return ;
if(c[j]+x<=b[i])return ;
}
return ;
} int main(){
int i;
RD3(p,q,l);
RD(r);
REP(i,p)RD2(a[i],b[i]);
REP(i,q)RD2(c[i],d[i]);
int ans=;
FOR(i,l,r){
if(gank(i)){
// printf("%d!",i);
ans++;
}
}
WN(ans);
return ;
}

C

找规律,发现4一种5一种,更高的可以两个相邻相减搞成1,随便搞。

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define mp make_pair
#define pb push_back void farm(int n) {
if(n<=) {
puts("NO");
return;
}
puts("YES");
while(n>) {
printf("%d - %d = 1\n",n,n-);
puts("4 * 1 = 4");
n-=;
}
if(n==) {
puts("4 * 3 = 12\n1 * 2 = 2\n2 * 12 = 24");
} else {
puts("5 - 3 = 2\n2 * 4 = 8\n2 + 1 = 3\n3 * 8 = 24");
}
} int main() {
int n;
RD(n);
farm(n);
return ;
}

D

过初审,爆炸了,还不会

发现我居然过了,不过我也不记得是啥题了怎么做的了,贴代码好了

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define mp make_pair
#define pb push_back int d[];
int c[];
int f[];
int n,ab[]; map<int,int>S; int getfather(int x){
int t=f[x]!=x?getfather(f[x]):x;
f[x]=t;
return t;
}
void comb(int x,int y){
f[getfather(y)]=getfather(x);
} int gank(int x) {
int q=d[x];
int xa=S[ab[]-q];
int xb=S[ab[]-q];
if(xa!= && xb!=){
int fx=getfather(x);
int fxa=getfather(xa);
int fxb=getfather(xb);
if(fx>n && fxa>n && fx!=fxa)return -;
if(fx!=fxa) fx>fxa?comb(fx,fxa):comb(fxa,fx);
fx=getfather(x);
if(fx>n && fxb>n && fx!=fxb)return -;
if(fx!=fxb) fx>fxb?comb(fx,fxb):comb(fxb,fx);
}else if(xa!=){
int fx=getfather(x);
int fxa=getfather(xa);
if(fx==n+ || fxa==n+)return -;
if(fx!=n+)comb(n+,fx);
if(fxa!=n+)comb(n+,fxa);
}else if(xb!=){
int fx=getfather(x);
int fxb=getfather(xb);
if(fx==n+ || fxb==n+)return -;
if(fx!=n+)comb(n+,fx);
if(fxb!=n+)comb(n+,fxb);
}else return -;
return ;
} bool farm() {
if(ab[]==ab[])ab[]=1e9*+;
int i,j;
mf1(c);
FOR(i,,n+)f[i]=i;
///n+1��setA��n+2��setB
FOR(i,,n) {
if(gank(i)==-)return ;
//printf("%d f[1]=%d\n",i,getfather(1));
}
set<int>A;
int b[],r=;
A.clear();
int cnt=;
FOR(i,,n){
int fi=getfather(i);
if(fi!=n+ && fi!=n+){
int xa=S[ab[]-d[i]];
int xb=S[ab[]-d[i]];
if(xb!= && (getfather(xb)==n+ || i==xa))comb(n+,fi);
else if(xa!= && (getfather(xa)==n+ || i==xb)) comb(n+,fi);
else return ;
}
//printf("f[%d] = %d\n",i,f[i]);
}
return ;
} int main() {
int i;
RD3(n,ab[],ab[]);
FOR(i,,n) {
RD(d[i]);
S[d[i]]=i;
}
if(farm()) {
puts("YES");
if(n>)printf("%d",getfather()-n-);
FOR(i,,n)printf(" %d",getfather(i)-n-);
} else puts("NO");
return ;
}
上一篇:UVA 11732 strcmp() Anyone? (压缩版字典树)


下一篇:sublime代码片段