codeforces 214C Game
来源:互联网 发布:牛鼻铣刀编程计算 编辑:程序博客网 时间:2024/04/30 15:09
直接暴力就行了。。。
其实关键还是在s=(s+1)%3;res++;这两句上啊T T
http://codeforces.com/problemset/problem/214/C
#include <iostream>#include <stdio.h>#include <string.h>#include <vector>#include <algorithm>#include <queue>#include <math.h>#include <stack>using namespace std;const int INF=1000000;int getInt(){ char ch=getchar(); while(ch<'0'||ch>'9')ch=getchar(); int num=0; while(ch>='0'&&ch<='9'){ num=num*10+ch-'0'; ch=getchar(); } return num;}const int maxn=222;int a[maxn];vector<int> v[maxn];int f[maxn];int n,m;int judge(int j){ //cout<<-1<<endl; for(int i=0; i < v[j].size();i++) if(f[v[j][i]]==0) return 0; //cout<<1<<endl; return 1;}int main(){ int i,j; cin>>n; for(i=1;i<=n;i++) { a[i]=getInt(); a[i]--; } for(i=1;i<=n;i++) { m=getInt(); v[i].resize(m); for(j=0;j<m;j++) v[i][j]=getInt(); } int s,pos,res,vis; int ans=INF; for(i=0;i<3;i++) { //cout<<k<<endl; memset(f,0,sizeof(f)); s=i; pos=0,res=0 ; //cout<<n<<endl; while(pos<n) { //cout<<pos<<endl; vis=pos; for(j=1;j<=n;j++) { //cout<<i<<endl; if(a[j]==s && f[j]==0 && judge(j)) { res++; pos++; f[j]=1; //cout<<i<<endl; } } if(vis==pos) { s=(s+1)%3; res++; } } ans=min(ans,res); //cout<<ans<<endl; } cout<<ans<<endl; return 0;}
0 0
- codeforces 214C Game
- Codeforces 214C Game【思维+拓扑排序】
- 【CODEFORCES】 C. 24 Game
- codeforces C. Beaver Game 博弈
- CodeForces 469C - 24 Game
- codeforces 78C. Beaver Game
- codeforces 245C Game with Coins
- codeforces 298 C Parity Game 思维问题
- codeforces 388C Fox and Card Game
- Codeforces 388 C. Fox and Card Game
- CodeForces 388C Fox and Card Game
- codeforces--C. Predict Outcome of the Game
- CodeForces 482C Game with Strings
- Codeforces Round 469 C 24 Game
- Codeforces #180 div2 C Parity Game
- codeforces 245C Game with Coins
- CodeForces 245C Game with Coins
- Codeforces 482C Game with strings
- 【转】Android异步消息处理机制完全解析,带你从源码的角度彻底理解
- hdu 1973 Prime Path 解题报告
- 骆驼命名法,帕斯卡命名法与下划线命名法
- Xcode中にSVNを使う方法
- U-boot分析与移植(6)----U-boot--Makefile
- codeforces 214C Game
- XE5 android怎么调用自带浏览器打开网页
- asterisk libxml2
- spring+springdatajpa+freemarker
- Java基础知识6
- 使用XmlDocument创建XML文档及增加删除更新节点
- 雾林盟主
- 算法概论思维导图
- IE8或者9---BEX错误解决方法