SDNU_ACM_ICPC_2017_Winter_Practice_3th
来源:互联网 发布:《python编程实践》 编辑:程序博客网 时间:2024/06/02 05:44
A SPOJ EASYMRKS Easy Marks
B SPOJ CANDY Candy I
输入第一行N。
N行每一行每个人的糖果数量。
最后求每个人糖果一样需要移动的糖果数量如果不能平均输出-1。
先求和sum然后判断sum%N==0如果不等于则不能平均分输出-1。如果==0然后求平均值b循环当a[i]>b则num+=a[i]-b。
/*********************author : MengFanzhuang*********************/#include <cstdio>#include <iostream>using namespace std;int main(){ int N; while(scanf("%d",&N)!=EOF&&N!=-1) { int a[10005]={0},sum=0; for(int j=0;j<N;++j) { scanf("%d",&a[j]); sum+=a[j]; } if(sum%N!=0) cout<<"-1"<<endl; else { int b=sum/N,num=0; for(int i=0;i<N;++i) { if(a[i]>b)num+=(a[i]-b); } cout<<num<<endl; } } return 0;}
C UVA 10346 Peter’s Smokes
输入n支烟然后每k个烟头可以组成一支新烟最后输出吸烟的数量。
wa几次之后开始胡乱改最后静下心来又分析了一下才改对。
/*********************author : MengFanzhuang*********************/#include <cstdio>#include <iostream>using namespace std;int main(){ int a,b; while(scanf("%d%d",&a,&b)!=EOF) { int num=a; //初始化num=a while(a>=b) { num+=a/b; //a/b是a个烟头组成新烟的数量 int c=a/b; //存一下新烟的数量 a%=b; //剩下烟头的数量 a+=c; //再加上新烟的数量 } cout<<num<<endl; } return 0;}
D SPOJ AE00 Rectangles
E UVA 12708 GCD The Largest
F CodeForces 304A Pythagorean Theorem II
G URAL 1573 Alchemy
组合数
输入第一行b r y表示各颜料数量。
下面的blue red yellow每出现一个表示每次需要用到的b r y颜料。
统计blue red yellow分别出现的次数b1 r1 y1然后求 C(b,b1)*C(r,r1)*C(y,y1)。
/*********************author : MengFanzhuang*********************/#include <cstdio>#include <iostream>#include <cstring>using namespace std;long long C(int n,int r){ if(r==0) return 1; else return C(n,r-1)*(n-r+1)/r;}int main(){ int b,r,y; while(scanf("%d%d%d",&b,&r,&y)!=EOF) { int k; int b1,r1,y1; b1=r1=y1=0; scanf("%d",&k); for(int i=0; i<k; ++i) { char a1[10]; scanf("%s",a1); if(strcmp(a1,"Red")==0) r1++; else if(strcmp(a1,"Blue")==0) b1++; else if(strcmp(a1,"Yellow")==0) y1++; } if(r1>r/2) r1=r-r1; if(b1>b/2) b1=b-b1; if(y1>y/2) y1=y-y1; long long a=C(r,r1)*C(b,b1)*C(y,y1); cout<<a<<endl; } return 0;}
H URAL 1022 Genealogical Tree
拓扑排序
输入第一行N N个数。
N行 第i行表示排在i后面的数。
最后输出正确的序列。
用队列做的wa了好多次因为这个题可能存在多解然后输出任意一个解就可以。
5
0
1 0
1 0
1 0
1 0
比如这个我写的那个队列就处理不了。
/*********************author : MengFanzhuang*********************/#include <cstdio>#include <iostream>using namespace std;int main(){ int n; while(scanf("%d",&n)!=EOF) { int a[105][105]= {0}; int b,in[105]= {0},num[105]; for(int i=1; i<=n; ++i) { while(scanf("%d",&b),b) { a[i][b]=1; in[b]++; } } int j=0,flag=0; for(int i=1; i<=n; ++i) { for(int i1=1; i1<=n; ++i1) { if(in[i1]==0) { if(flag) cout<<" "; cout<<i1; flag=1; in[i1]=-1; for(int i2=1; i2<=n; ++i2) { if(a[i1][i2]) { in[i2]--; } } break; } } } cout<<endl; } return 0;}
队列处理虽然不对但还是备份一下。
/*********************author : MengFanzhuang*********************/#include <cstdio>#include <iostream>#include <vector>#include <queue>using namespace std;int main(){ int n; while(scanf("%d",&n)!=EOF) { vector<int> a[105]; int b,in[105]= {0}; for(int i=1; i<=n; ++i) { while(scanf("%d",&b)!=EOF&&b) { a[i].push_back(b); in[b]++; } } queue<int> q; for(int i=1; i<=n; ++i) { if(in[i]==0) { q.push(i); cout<<i; in[i]=-1; break; } } while(!q.empty()) { int temp=q.front(); q.pop(); for(int i=0; i<a[temp].size(); ++i) { in[a[temp][i]]--; if(in[a[temp][i]]==0) { q.push(a[temp][i]); in[a[temp][i]]=-1; cout<<" "<<a[temp][i]; } } for(int i=1; i<=n; ++i) { if(in[i]==0) { q.push(a[temp][i]); in[a[temp][i]]=-1; cout<<" "<<a[temp][i]; } } } cout<<endl; } return 0;}
I CodeForces 758B Blown Garland
0 0
- SDNU_ACM_ICPC_2017_Winter_Practice_3th
- Ember基础环境搭建
- AHOI2009中国象棋--巧妙dp
- HDU3188-Just A Triangle
- HashMap扩容
- 机器学习方法学习与比较--KNN
- SDNU_ACM_ICPC_2017_Winter_Practice_3th
- Python基础
- 一边搭建一边理解MongoDB副本集(副本集选举)
- 神经网络-CNN结构和语音识别应用
- Leetcode 312 - Burst Balloons(区间dp)
- 博为峰Java技术文章 ——JavaSE Swing SpringLayout布局管理器II
- HDU1195-Open the Lock
- 读《暗时间》有感(二)
- More Effective C++学习笔记(6)-杂项