Codeforces Round #216 (Div. 2) 解题报告
2013-11-30 09:11
441 查看
Problem A Valera and Plates
有碗和碟子两种容器,小明每天吃一种食物,食物有两种1只能用碗吃2两个容器都可。给你初始的碗与碟子问小明至少要洗多少个碗或碟子。
简单模拟,能用碟子就用碟子。
代码如下:
View Code
有碗和碟子两种容器,小明每天吃一种食物,食物有两种1只能用碗吃2两个容器都可。给你初始的碗与碟子问小明至少要洗多少个碗或碟子。
简单模拟,能用碟子就用碟子。
代码如下:
#include <iostream> #include <fstream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <utility> #include <vector> #include <queue> #include <stack> #define INF 0x7fffffff #define LEN 101000 #define ll long long #define eps 1E-6 using namespace std; vector<pair<int,int> > Map[LEN]; int n, vis[LEN], vv[LEN]; int DFS(int root, int fa) { int ret = 0, flag = 1; for(int i=0; i<Map[root].size(); i++){ // if(vv[i])continue; // vv[i] = 1; if(Map[root][i].first==fa){ flag = Map[root][i].second; continue; } ret+=DFS(Map[root][i].first, root); } if(ret==0 && flag==2)return vis[root]=1; return ret; } int main() { // freopen("in.txt", "r", stdin); while(scanf("%d", &n)!=EOF){ memset(vis, 0, sizeof vis); memset(vv, 0, sizeof vv); for(int i=0; i<LEN; i++)Map[i].clear(); for(int i=1; i<n; i++){ //build Map int a, b, val; scanf("%d%d%d", &a, &b, &val); Map[a].push_back(make_pair(b, val)); Map[b].push_back(make_pair(a, val)); } int ans = DFS(1, -1); printf("%d", ans); for(int i=1; i<=n; i++){ if(vis[i]){ printf(" %d", i); } } printf("\n"); } return 0; }
View Code
相关文章推荐
- Codeforces Round #380 (Div. 2) 解题报告
- Codeforces Round #235 (Div. 2) D. Roman and Numbers 解题报告(状态压缩)
- Codeforces Round #369 (Div. 2) 解题报告(A,B,C)
- Codeforces Round #238 (Div. 1) 解题报告
- topcoder SRM588 DIV1 解题报告
- codeforces Round #238(div2) d解题报告
- codeforces Round #267(div2) B解题报告
- Codeforces Round #273 (Div. 2) 解题报告 (A B C D)
- codeforces Round #274(div2) C解题报告
- codeforces Round #261(div2) E解题报告
- 解题报告:Codeforces Round #433 (Div. 2) E. Boredom ( 离线处理+树状数组)
- Codeforces Round #339 (Div. 2) 解题报告
- Codeforces Round #407 (Div. 2)解题报告
- Codeforces Round #341 (Div. 2) 解题报告
- Codeforces Round #342 (Div 2) 解题报告
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) 解题报告
- Croc Champ 2013 - Round 2 (Div. 2 Edition) E. Cube Problem 解题报告
- Codeforces Round #401 (div. 2)解题报告
- 【解题报告】Codeforces Round #301 (Div. 2) 之ABCD
- CF 188 div2 解题报告