CodeForces#207Div.2 - B. Flag Day
来源:互联网 发布:房子平面图设计软件 编辑:程序博客网 时间:2024/05/20 03:44
初始化所有人都没有跳过舞。
判断一组里面第一个出现的之前跳过舞的人,让其他两个人的颜色为这个跳过舞的人的颜色后两位(在1,2,3之间循环)。若加和完之后大于3,自减3 。若全部人之前都没有跳过舞,直接赋值1,2,3 。
AC代码:
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int color[100005];int main() { int n, m; while(scanf("%d%d", &n, &m)!=EOF) { int a, b, c; memset(color, 0, sizeof(color)); for(int i = 1; i <= m; i++) { scanf("%d%d%d", &a, &b, &c); if(color[a] != 0) { color[b] = color[a] + 1; color[c] = color[a] + 2; if(color[b] > 3) color[b] -= 3; if(color[c] > 3) color[c] -= 3; } else if(color[b] != 0) { color[a] = color[b] + 2; color[c] = color[b] + 1; if(color[a] > 3) color[a] -= 3; if(color[c] > 3) color[c] -= 3; } else if(color[c] != 0) { color[a] = color[c] + 1; color[b] = color[c] + 2; if(color[a] > 3) color[a] -= 3; if(color[b] > 3) color[b] -= 3; } else { color[a] = 1; color[b] = 2; color[c] = 3; } } for(int i = 1; i <= n; i++) { if(i == 1) printf("%d", color[i]); else printf(" %d", color[i]); } printf("\n"); } return 0;}
简化一下代码量:
#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int c[100005];int n,m,x,y,z;int main(){ while(~scanf("%d%d",&n,&m)) { memset(c,0,sizeof(c)); while(m--) { scanf("%d%d%d",&x,&y,&z); if(c[x]!=0) { c[y]=c[x]%3+1; c[z]=c[y]%3+1; } else if(c[y]!=0) { c[z]=c[y]%3+1; c[x]=c[z]%3+1; } else if(c[z]!=0) { c[x]=c[z]%3+1; c[y]=c[x]%3+1; } else { c[x]=1; c[y]=2; c[z]=3; } } for(int i=1;i<=n;i++) printf("%d ",c[i]);puts(""); } return 0;}
- CodeForces#207Div.2 - B. Flag Day
- codeforces 357B Flag Day
- codeforces#357B. Flag Day
- B. Flag Day
- 【codeforce】B. Flag Day
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B - Bash's Big Day 枚举
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) -- B. Bash's Big Day (唯一分解定理)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B. Bash's Big Day 数论+贪心
- Codeforces #261 Div 2 B
- codeforces #368 div.2B
- Codeforces--477Div.2--B
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B. Bash's Big Day(分拆素因子+求最多的公因子)
- codeforces 837B Flag of Berland
- Codeforces Round #332 (Div. 2) C. Day at the Beach
- Codeforces Round #332 (Div. 2) C. Day at the Beach
- Codeforces Round #332 (Div. 2) C. Day at the Beach
- Codeforces Round #332 (Div. 2) C. Day at the Beach
- Codeforces Round #332 (Div. 2)-C. Day at the Beach
- 单例 singleton
- 小白鼠检验毒水问题
- Leetcode Remove Duplicates from Sorted Array
- OCP-1Z0-052-V8.02-45题
- uva 12661 - Funny Car Racing
- CodeForces#207Div.2 - B. Flag Day
- java提高篇(一)-----理解java的三大特性之封装
- 一次Linux服务器被hack的过程分析
- 动态验证
- sysfs文件系统
- 【每天学点算法题10.15】求两个数的最大公约数
- Xcoding
- 操作系统的环境变量
- Android项目结构 以及体系结构