Codeforces Round #181 (Div. 2) 部分解题报告
来源:互联网 发布:淘宝手机壳店铺 编辑:程序博客网 时间:2024/05/19 22:58
思想总结:
上次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 Round #181 (Div. 2) 部分解题报告
- Codeforces Round #149 (Div. 2)解题报告
- Codeforces Round #180 (Div. 2) 解题报告
- Codeforces Round #190 (Div. 2) 解题报告
- Codeforces Round #191 (Div. 2) 解题报告
- Codeforces Round #189 (Div. 2) 解题报告
- Codeforces Round #142 (Div. 2) 解题报告
- Codeforces Round #229 (Div. 2) 解题报告
- Codeforces Round #241 (Div. 2) 解题报告
- Codeforces Round #262 (Div. 2)解题报告
- Codeforces Round #267 (Div. 2) 解题报告
- Codeforces Round #266 (Div. 2)解题报告
- Codeforces Round #268 (Div. 2) 解题报告
- Codeforces Round #271 (Div. 2) 解题报告
- Codeforces Round #274 (Div. 2) 解题报告
- Codeforces Round #276 (Div. 2) 解题报告
- Codeforces Round #277 (Div. 2) 解题报告
- Codeforces Round #224 (Div. 2)解题报告
- Hibernate 帮助类
- DP与贪心算法的一点浅见
- 设置 OSD可以在 Windows start 上显示
- 气死男生的对话
- 动作类测试
- Codeforces Round #181 (Div. 2) 部分解题报告
- ant与yui压缩静态文件
- C#数据查询帮助类
- Codeforce#181 div2 C,E--problem 300E,300C
- 【转】SSH框架总结(框架分析+环境搭建+实例源码下载)
- Asp.net Ajax,Jquery,ExtJs 三种Ajax技术框架比较
- 安装最新版本的CMake
- android开发AlarmManager详解
- oracle锁