Codeforces Round #181 (Div. 2) 部分解题报告
2013-04-26 12:06
363 查看
思想总结:
上次rating 略微涨了一点,这次心急。连a题的样例都没仔细查对,就wa了一次。并且老毛病,改代码不细想。
b题,并查集也搞了好久,不熟练。然后处理集合一直处于想清楚,没想清楚的混沌状态。然后一个条件判断错了。早上起来想哪里没处理清楚。原来是负数也能被一个数整除。没细想。
c题,据说是数位dp。不会,去年暑假集训有一个打标题是dp。但打表ac后,就没管了。。。
要学习的东西很多啊。。。
http://www.codeforces.com/contest/300
a题水题;
b题,就是一个并查集再加点想法,如果一个集合是3个元素的话,直接输出这个集合中的元素,如果这个集合只有2个元素的话, 就要找一个只有一个元素的集合,一起输出。
上次rating 略微涨了一点,这次心急。连a题的样例都没仔细查对,就wa了一次。并且老毛病,改代码不细想。
b题,并查集也搞了好久,不熟练。然后处理集合一直处于想清楚,没想清楚的混沌状态。然后一个条件判断错了。早上起来想哪里没处理清楚。原来是负数也能被一个数整除。没细想。
c题,据说是数位dp。不会,去年暑假集训有一个打标题是dp。但打表ac后,就没管了。。。
要学习的东西很多啊。。。
http://www.codeforces.com/contest/300
a题水题;
#include<cstdlib> #include<algorithm> #include<cstdio> //#inclu #include<iostream> using namespace std; int a[5566]; int main() { int n; while(cin>>n) { for(int j=0;j<n ;j++) cin>>a[j]; sort(a,a+n); if(a[0]<0&& a[n-1]>0){ cout<<"1 " <<a[0]<<endl; cout<<"1 "<<a[n-1]<<endl; cout<<n-2 ; for(int j=1;j<n-1;j++) cout<<" "<<a[j]; cout<<endl; } else { cout<<"1 "<< a[0]<<endl; cout<<"2 " <<a[1]<<" "<<a[2]<<endl; cout<<n-3; for(int j=3;j<n;j++) cout<<" "<<a[j]; cout<<endl; } } return 0; }
b题,就是一个并查集再加点想法,如果一个集合是3个元素的话,直接输出这个集合中的元素,如果这个集合只有2个元素的话, 就要找一个只有一个元素的集合,一起输出。
#include<cstdlib> #include<algorithm> #include<cstdio> //#inclu #include<iostream> using namespace std; int f[1000]; int find(int x) { int t=x; while(f[t] > 0) t=f[t]; //f[x] = (f[x] < 0 ? f[x] : find(f[x])); return t; } void merge(int x,int y) { if(find(x) == find(y) ) return ; int t=f[ find(x) ] + f [find(y) ]; f[find(x)] = y; f[find(y)] = t; } int main() { int n,m,t; int j,i,k,l; int x,y; int one,two,three,four; while(cin>>n>>m){ for(j=1;j<=n;j++) f[j]=-1; four=one=two=three=0; for(j=0;j<m;j++){ cin>>x>>y; merge(x,y); } for(j=1;j<=n;j++) if(f[ find(j)] == -1) one++; else if(f[find(j)] == -2) two++; else if(f[find(j)] == -3) three++; else four++; two/=2; three/=3; if(four>0) { cout<<"-1"<<endl; continue; } /* if(one != 0 &&(one -two) < 0 ) { cout<<"-1"<<endl; //cout<< "-1"<<one<<" "<<two<<endl; continue; } if(one == 0 && two != 0) { cout<<"-1"<<endl; //cout<<"-1"<<"llkjkljljlk"<<endl; continue; } */ if(two != 0 && one - two <0){ cout<<"-1"<<endl; continue; } else { j=1; k=2; l=3; while(three--) { for(;j<n+1;j++) for(k=j+1;k<n+1;k++) for(l=k+1;l<n+1;l++) if(j !=k && j!=l && k!=l && find(j)==find(k)&&find(j)== find(l) && f[find(j)] == -3){ cout<<j<<" "<<k<<" "<<l << endl; f[find(j)] = -432; goto out1; } out1:; } t=1; while(f[find(t)]!=-1 && t <=n) t++; j=1; k=2; while(two--){ for(;j<n+1;j++) for(k=j+1;k<n+1;k++) if(j!=k && find(j)== find(k) && f[find(j)]== -2){ f[find(j)]= -3423; cout<<j<<" "<<k<<" " <<t<< endl; goto out2; } out2: t++; while(f[find(t)]!=-1 && t<=n)t++; one--; } j=n; while(one>0){ while(f[find(j)] != -1 ) j--; cout<<j; j--; while(f[find(j)] != -1 ) j--; cout<<" "<<j; j--; while(f[find(j)] != -1) j--; cout<<" " << j<<endl; j--; one--; one--; one--; } } } return 0; }
相关文章推荐
- Codeforces Beta Round #95 (Div. 2) 部分解题报告 (dp,组合数,)
- Croc Champ 2012 - Round 2 (Unofficial Div. 2 Edition) 部分解题报告。
- 【解题报告】Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
- 解题报告:Codeforces Round #362 (Div. 1) A. Lorenzo Von Matterhorn 树状概率DP
- 2014 UESTC 暑前集训队内赛(3) 部分解题报告
- 【解题报告】Codeforces Round #301 (Div. 2) 之ABCD
- Codeforces 474(#271 Div 2) 解题报告
- Codeforces Round #230 (Div. 2) 解题报告
- codeforces Round #263(div2) D解题报告
- codeforces Round #274(div2) B解题报告
- Code+ 12月月赛Div 2解题报告
- Codeforces Round #231 (Div2) 迟到的解题报告
- [占坑]Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2) 解题报告
- Codeforces Round #290 (Div. 2) 解题报告 A.B.C.D.
- 【解题报告】Codeforces Round #360 (Div. 2)
- Codeforces Round #143 (Div. 2) C (解题报告)
- Codeforces Round #383 (Div. 1) Problem B.Arpa's weak amphitheater and Mehrdad's valuable Hoses 解题报告
- 【解题报告】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
- codeforces Round #258(div2) B解题报告
- Codeforces 448(#256 (Div. 2) ) 解题报告