Codeforces 982 樹邊兩端點計數偶數連通塊 鯊魚活動最小K最大location
阿新 • • 發佈:2018-05-18
str cto cout force sig one memset air c++
A
/*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; const ll LLmaxn = 2e18; const int N = 100005; inline int readint() { char c = getchar(); int ans = 0; whileView Code(c < ‘0‘ || c > ‘9‘) { c = getchar(); } while (c >= ‘0‘ && c <= ‘9‘) { ans = ans * 10 + c - ‘0‘, c = getchar(); } return ans; } int main() { int n; n = readint(); string a; cin>> a; if (a.size() == 1) { if (a[0] == ‘0‘) { cout << "No" << endl; } else { cout << "Yes" << endl; } }else { if (a[0] + a[1] != ‘0‘ + ‘1‘) { cout << "No" << endl; return 0; } if (a[a.size() - 1] + a[a.size() - 2] != ‘0‘ + ‘1‘) { cout << "No" << endl; return 0; } for (int i = 1; i < a.size() - 1; i++) { if (a[i] == ‘0‘) { if (a[i - 1] == ‘0‘ && a[i + 1] == ‘0‘) { cout << "No" << endl; return 0; } } else { if (a[i - 1] == ‘1‘ || a[i + 1] == ‘1‘) { cout << "No" << endl; return 0; } } } cout<<"Yes"<<endl; } return 0; }
B
/*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; const ll LLmaxn = 2e18; const int N = 200005; inline int readint() { char c = getchar(); int ans = 0; while (c < ‘0‘ || c > ‘9‘) { c = getchar(); } while (c >= ‘0‘ && c <= ‘9‘) { ans = ans * 10 + c - ‘0‘, c = getchar(); } return ans; } priority_queue<pair<int, int>, vector<pair<int, int> >, less<pair<int, int> > > quemax; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > quemin; int visit[N]; int main() { int now; pair<int, int> cnt; int n; cin >> n; for (int i = 1; i <= n; i++) { now = readint(); quemin.push(make_pair(now, i)); } string a; cin >> a; int value, aim; for (int i = 0; i < a.size(); i++) { if (a[i] == ‘0‘) { cnt=quemin.top(); quemin.pop(); cout<<cnt.second<<" "; quemax.push(cnt); } else { cnt=quemax.top(); quemax.pop(); cout<<cnt.second<<" "; } } return 0; }View Code
C
/*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; const ll LLmaxn = 2e18; const int N = 100005; inline int readint() { char c = getchar(); int ans = 0; while (c < ‘0‘ || c > ‘9‘) { c = getchar(); } while (c >= ‘0‘ && c <= ‘9‘) { ans = ans * 10 + c - ‘0‘, c = getchar(); } return ans; } vector<int> f[N]; int du[N]; int ans[N]; int n; int u, v; int aim; int number = 0; int getans(int x, int pre) { ans[x] = 1; int len = f[x].size(); if (len == 1 && x != aim) { return ans[x]; } for (int i = 0; i < len; i++) { int to = f[x][i]; if (to == pre) { continue; } getans(to, x); ans[x] += ans[to]; } if(ans[x]%2==0&&ans[x]!=n) number++; return ans[x]; } int main() { n = readint(); if (n % 2) { cout << -1 << endl; return 0; } for (int i = 1; i <= n - 1; i++) { u = readint(), v = readint(); f[u].push_back(v); f[v].push_back(u); du[u]++, du[v]++; } for (int i = 1; i <= n; i++) { if (du[i] == 1) { aim = i; getans(i, -1); break; } } cout<<number<<endl; return 0; }View Code
D
Codeforces 982 樹邊兩端點計數偶數連通塊 鯊魚活動最小K最大location