当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 【队伍训练】Codeforces Round #660 (Div. 2)

【队伍训练】Codeforces Round #660 (Div. 2)

2020年08月11日  | 移动技术网IT编程  | 我要评论
A思维#pragma GCC target("avx,sse2,sse3,sse4,popcnt")#pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math")#include <bits/stdc++.h>using namespace std;#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)typedef long lon

A
思维

#pragma GCC target("avx,sse2,sse3,sse4,popcnt") #pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math") #include <bits/stdc++.h> using namespace std; #define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll MOD = 1e9 + 7; inline ll read() { ll s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); } while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); return s * w; } inline void write(ll x) { if (!x) { putchar('0'); return; } char F[40]; ll tmp = x > 0 ? x : -x; if (x < 0)putchar('-'); int cnt = 0; while (tmp > 0) { F[cnt++] = tmp % 10 + '0'; tmp /= 10; } while (cnt > 0)putchar(F[--cnt]); } inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll qpow(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans *= a; b >>= 1; a *= a; } return ans; } ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; } inline int lowbit(int x) { return x & (-x); } int main(){ int t; cin>>t; while(t--){ int n; cin>>n; if(n<=30) cout<<"NO"<<endl; else if(n==36) cout<<"YES\n"<<"5 6 10 15"<<endl; else if (n==40) cout<<"YES\n"<<"2 6 10 22"<<endl; else if (n==44) cout<<"YES\n"<<"2 6 10 26"<<endl; else cout<<"YES\n"<<"6 10 14 "<<n-30<<endl; } } 

B
观察

#pragma GCC target("avx,sse2,sse3,sse4,popcnt") #pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math") #include <bits/stdc++.h> using namespace std; #define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll MOD = 1e9 + 7; inline ll read() { ll s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); } while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); return s * w; } inline void write(ll x) { if (!x) { putchar('0'); return; } char F[40]; ll tmp = x > 0 ? x : -x; if (x < 0)putchar('-'); int cnt = 0; while (tmp > 0) { F[cnt++] = tmp % 10 + '0'; tmp /= 10; } while (cnt > 0)putchar(F[--cnt]); } inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll qpow(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans *= a; b >>= 1; a *= a; } return ans; } ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; } inline int lowbit(int x) { return x & (-x); } int main(){ int t; cin>>t; int n; while(t--){ cin>>n; int len=4*n-n; for (int i=0;i<(len/4);i++) cout<<9; for (int i=(len/4);i<n;i++) cout<<8; cout<<endl; } return 0; } 

C
dfs
这题卡时间较长

#include<bits/stdc++.h> #define maxn 100100 using namespace std; vector<int> g[maxn]; int happy[maxn]; int all[maxn]; int diff[maxn]; int flag; int f; void dfs(int v, int p) { int h = 0,k = 0; for (auto u : g[v]){ k += 1; if (u == p) { continue; } dfs(u, v); all[v] += all[u]; h += happy[u]; } happy[v] = all[v] - (all[v] - diff[v]) / 2; if (happy[v] < h || happy[v]<0||happy[v]>all[v] || all[v]%2!=(diff[v]%2+2)%2) { f = 0; } } int main(){ int t; cin>>t; while(t--){ f = 1; int n,m; cin>>n>>m; for (int i = 0; i < n; i++) { cin >> all[i];//每个人住在哪  g[i].clear(); } for (int i = 0; i < n; i++) { cin >> diff[i];//给定的对照值  } for (int i=0;i<n-1;i++){//建图  int a, b; cin>>a>>b; a--; b--; g[a].push_back(b); g[b].push_back(a); } dfs(0, -1); if(f) cout << "YES"<<endl; else cout << "NO" <<endl; } return 0; } 

D
不太理解,队友做了

本文地址:https://blog.csdn.net/qq_45585519/article/details/107900593

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网