Google APAC 2016 University Graduates Test(google校招笔试)
来源:互联网 发布:php代码批量替换工具 编辑:程序博客网 时间:2024/05/17 08:32
Problem A. Bad Horse
题意:给n个关系,每个关系有两个人,要求把这些人分成两组,每组里的人之间都没有关系。
二分图染色即可。关系=边,人=点。
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<queue>#include<set>#include<map>#include<vector>#include<cmath>#define ll __int64#define INF 0x3fffffffusing namespace std;int G[105][105];int col[105];int k;bool bfs(int s) { queue<int> p; p.push(s); col[s] = 1; while(!p.empty()) { int from = p.front(); p.pop(); for(int i = 1; i <= k; i++) { if(G[from][i] && col[i] == -1) { p.push(i); col[i] = !col[from];//染成不同的颜色 } if(G[from][i] && col[from] == col[i])//颜色有相同,则不是二分图 return false; } } return true;}int main(){ //freopen("d:\\A-small-2-attempt0.in","r",stdin); //freopen("d:\\output.txt","w",stdout); int n,T,t=1; cin>>T; while(T--){ cin>>n; k=0; map<string,int>m; memset(G,0,sizeof(G)); memset(col, -1, sizeof(col)); for(int i=0;i<n;i++){ char a[105],b[105]; cin>>a>>b; if(!m[a]) m[a]=++k; if(!m[b]) m[b]=++k; G[m[a]][m[b]]=1; G[m[b]][m[a]]=1; } bool flag=false; for(int i=1;i<=k;i++){ if(col[i]==-1&&!bfs(i)){ flag=true; break; } } if(!flag) cout<<"Case #"<<t++<<": "<<"Yes"<<endl; else cout<<"Case #"<<t++<<": "<<"No"<<endl; } return 0;}<strong></strong>
Problem B. Captain Hammer
题意:给出斜抛运动的速度和水平位移,求斜抛角度。
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<queue>#include<set>#include<map>#include<vector>#include<cmath>#define ll __int64#define INF 0x3fffffffusing namespace std;int main(){ //freopen("d:\\Test.txt","r",stdin); //freopen("d:\\output.txt","w",stdout); int T,t=1; cin>>T; while(T--){ double v,d,c; cin>>v>>d; c=asin(9.8*d/v/v) * 180.0/3.1415926/2.0; cout<<"Case #"<<t++<<": "; printf("%.7f\n",c); } return 0;}
Problem C. Moist
题意:给n个字符串,要求按字典序排序,排序方法为从上往下扫,遇到一个比上面里的小的,就交换位置。求交换次数
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cstdlib>#include<algorithm>#include<queue>#include<set>#include<map>#include<vector>#include<cmath>#define ll __int64#define INF 0x3fffffffusing namespace std;char s[105][105];int n;int main(){ //freopen("d:\\C-small-2-attempt0.in","r",stdin); //freopen("d:\\output.txt","w",stdout); int T,t=1; cin>>T; while(T--){ cin>>n; getchar(); for(int i=0;i<n;i++){ gets(s[i]); } int ans=0; for(int i=0;i<n;i++){ for(int j=0;j<i;j++){ if(strcmp(s[j],s[i])>0){ swap(s[j],s[i]); ans++; break; } } } cout<<"Case #"<<t++<<": "<<ans<<endl; } return 0;}
0 0
- Google APAC 2016 University Graduates Test(google校招笔试)
- Google APAC 2016 University Graduates Test Practice Round APAC test
- Google APAC 2016 University Graduates Test Round A
- Google APAC 2016 University Graduates Test Round A解题报告
- Google APAC 2016 University Graduates Test Round B解题报告
- Google APAC 2016 University Graduates Test Round C解题报告
- Google APAC 2016 University Graduates Test Round D解题报告
- Google APAC 2016 University Graduates Test Round D
- [ Google APAC 2015 University Graduates Test ] Round C APAC Test
- " Server error. Please try again. "Google APAC 2015 University Graduates Test解决方法
- Problem D. gMatrix Google APAC 2016 University Test Round C
- Problem B. gFiles Google APAC 2016 University Test Round C
- Problem A. gRanks Google APAC 2016 University Test Round C
- Problem B. gBalloon Google APAC 2016 University Test Round D
- Problem A. Travel Google APAC 2016 University Test Round B
- Problem B. gWheels Google APAC 2016 University Test Round B
- Problem C. gNumbers Google APAC 2016 University Test Round B
- Problem B. gCube Google APAC 2016 University Test Round A
- Java基础 笔记(1)
- 类的其他成员
- Hive启动报错无法找到class— java.lang.NoClassDefFoundError
- 字符串匹配算法---KMP算法
- Ubuntu14.04_X64 + ATI显卡 安装Caffe
- Google APAC 2016 University Graduates Test(google校招笔试)
- EATool-输电线路房屋分布图
- 背包之01背包、完全背包、多重背包详解(转)
- 图像处理
- Android 保存View到本地SD卡
- 2016年 成渝校招软件上机练习
- Palindrome Number
- 操作系统过小,无法启动数据库
- TFHpple使用方法