hihoCoder 1135 Magic Box 微软2016校园招聘在线笔试
来源:互联网 发布:淘宝如何取消开店 编辑:程序博客网 时间:2024/04/28 21:59
这一题写了好久也是醉了。。直接模拟即可,注意difference是任意两个count的差,x,y,z不一定按照R,Y,B的顺序。
#include<iostream>#include<stdio.h>#include<cstdio>#include<stdlib.h>#include<vector>#include<string>#include<cstring>#include<cmath>#include<algorithm>#include<stack>#include<queue>#include<ctype.h>#include<map>#include<time.h>#include<bitset>#include<set>#include<list>using namespace std;//hiho 1135const int maxn=20010;char str[maxn];int x;int y;int z;int num[3];//0 for r, 1 for y, 2 for bint ans;bool judge(){// if(abs(num[0]-num[1])==x&&abs(num[1]-num[2])==y&&abs(num[2]-num[0])==z)// {// return true;// } bool flgx=false; bool flgy=false; bool flgz=false; pair<int,int>idxx; pair<int,int>idxy; for(int i=0;i<3;i++) { for(int j=i+1;j<3;j++) { if(abs(num[i]-num[j])==x) { flgx=true; idxx.first=i; idxx.second=j; break; } } } for(int i=0;i<3;i++) { for(int j=i+1;j<3;j++) { if(abs(num[i]-num[j])==y) { if(!(idxx.first==i&&idxx.second==j)) { flgy=true; idxy.first=i; idxy.second=j; break; } } } } for(int i=0;i<3;i++) { for(int j=i+1;j<3;j++) { if(abs(num[i]-num[j])==z) { if(idxx.first==i&&idxx.second==j) continue; if(idxy.first==i&&idxy.second==j) continue; flgz=true; break; } } } if(flgx&&flgy&&flgz) { return true; } return false;}int main(){ freopen("input.txt","r",stdin); //freopen("data.txt","r",stdin); //freopen("out1.txt","w",stdout); scanf("%d %d %d",&x,&y,&z); scanf("%s",&str); int len=strlen(str); ans=0; for(int i=0;i<len;i++) { if(str[i]=='R') { num[0]++; } else if(str[i]=='Y') { num[1]++; } else if(str[i]=='B') { num[2]++; } ans=max(ans,num[0]+num[1]+num[2]); // cout<<num[0]<<" "<<num[1]<<" "<<num[2]<<" "<<ans<<endl; if(judge()) { //cout<<"here"<<endl; memset(num,0,sizeof(num)); } } printf("%d\n",ans); return 0;}
0 0
- hihoCoder 1135 Magic Box 微软2016校园招聘在线笔试
- 题目1 : Magic Box【微软2016校园招聘在线笔试】
- 微软2016校园招聘在线笔试题目-第一题 Magic Box
- hihoCoder 1136 Professor Q's Software 微软2016校园招聘在线笔试
- hihocoder: 1239 Fibonacci(微软2016校园招聘9月在线笔试)
- hihocoder: 1239 Fibonacci(微软2016校园招聘9月在线笔试)
- [hihocoder 1238] Total Highway Distance(微软2016校园招聘9月在线笔试)
- hihocoder 1290 -- 微软2016校园招聘4月在线笔试-3-Demo Day
- hihocoder 1288:Font Size--微软2016校园招聘4月在线笔试
- 微软2016校园招聘4月在线笔试 hihocoder 1288 Font Size (模拟)
- 微软2016校园招聘4月在线笔试 hihocoder 1290 Demo Day (dp)
- 微软2016校园招聘4月在线笔试 hihocoder 1289 403 Forbidden
- [Hihocoder 1289] 403 Forbidden (微软2016校园招聘4月在线笔试)
- hihocoder 1289 微软2016校园招聘4月在线笔试-2:403 Forbidden
- HiHocoder #1136 : Professor Q's Software 微软2016校园招聘在线笔试 【拓扑排序+DP】
- hihocoder 1239 Fibonacci(微软2016校园招聘9月在线笔试)
- 微软2016校园招聘在线笔试: [Islands Travel]
- 微软2016校园招聘在线笔试第二场
- Tomcat连接池
- 排序算法总结
- 事务
- BufferedInputStream和BufferedOutputStream用法 解决乱码
- HDU--1711(KMP模板题)
- hihoCoder 1135 Magic Box 微软2016校园招聘在线笔试
- VS2010相关问题
- C++中的三种继承public,protected,private
- Linux启动过程
- 传智播客学习之HTML基础语法
- [移动] Android推送方案分析(MQTT/XMPP/GCM) 服务器的搭建
- eclipse中Maven项目pom.xml报错:com.thoughtworks.xstream.io.HierarchicalStreamDriver
- LeetCode: Tow Sum (JavaScript)
- Bootloader启动过程