2018浙江省省赛
A
保证先升后降,然后没有不合法的情况,就是Yes
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define debug freopen("in.txt","r",stdin),freopen("out.txt","w",stdout); #define pb push_back #define all(x) x.begin(),x.end() #define fs first #define sc second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; const int maxn = 1e6+10; const int maxM = 1e6+10; const int inf = 0x3f3f3f3f; const ll inf2 = 0x3f3f3f3f3f3f3f3f; template<class T>void read(T &x){ T s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); x = s*w; } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class T>void print(T x){ cout<<x<<" "; } template<class H, class... T> void print(H h, T... t) { print(h); print(t...); } int T,N; int a[maxn]; void solve(){ int up = 0,down = 0,ok = 1; for(int i = 2;i<=N;i++){ if(a[i] > a[i-1] && down == 0) up = 1; else if(a[i] < a[i-1] && up == 1) down = 1; else{ ok = 0; break; } } if(ok && up == 1 && down == 1) puts("Yes"); else puts("No"); } int main(){ // debug; read(T); while(T--){ read(N); for(int i = 1;i<=N;i++) read(a[i]); solve(); } return 0; }
B
暴力走一遍,记录s[i]-d[i]差值出现最多的次数,输出即可
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define debug freopen("in.txt","r",stdin),freopen("out.txt","w",stdout); #define pb push_back #define all(x) x.begin(),x.end() #define fs first #define sc second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; const int maxn = 1e6+10; const int maxM = 1e6+10; const int inf = 0x3f3f3f3f; const ll inf2 = 0x3f3f3f3f3f3f3f3f; template<class T>void read(T &x){ T s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); x = s*w; } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class T>void print(T x){ cout<<x<<" "; } template<class H, class... T> void print(H h, T... t) { print(h); print(t...); } int T,N; int d[maxn],s[maxn]; map<int,int> mp; void solve(){ mp.clear(); int ans = 0; for(int i = 1;i<=N;i++){ int c = s[i] - d[i]; mp[c]++; ans = max(ans,mp[c]); } printf("%d\n",ans); } int main(){ // debug; read(T); while(T--){ read(N); for(int i = 1;i<=N;i++) read(d[i]); for(int i = 1;i<=N;i++) read(s[i]); solve(); } return 0; }
J
sum = n*(n+1)/2
如果sum是奇数,肯定不能分成两部分,输出-1
如果是偶数,就要么n%4 == 3,n%4 == 0
如果n%4 == 1: 1 [2,3,4,5],6 7
,2和5,1和6分到G1,G3去
如果n%4 == 0: [1,2,3,4],[5,6,7,8]
1和4,5和8分成到G1,G3去
其余就分配到G2,G4去
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define debug freopen("in.txt","r",stdin),freopen("out.txt","w",stdout); #define pb push_back #define all(x) x.begin(),x.end() #define fs first #define sc second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; const int maxn = 1e6+10; const int maxM = 1e6+10; const int inf = 0x3f3f3f3f; const ll inf2 = 0x3f3f3f3f3f3f3f3f; template<class T>void read(T &x){ T s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); x = s*w; } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class T>void print(T x){ cout<<x<<" "; } template<class H, class... T> void print(H h, T... t) { print(h); print(t...); } int T,N; char s[maxn]; bool vis[100010]; int solve(){ for(int i = 1;i<=N;i++) vis[i] = 0; ll sum = N * (N + 1)/2; if(sum %2 == 1) return puts("-1"),0; if(N%4 == 3){ for(int i = 2;i<N-1;i+=4){ vis[i] = vis[i+3] = 1; } vis[1] = vis[N-1] = 1; }else{ for(int i = 1;i<=N;i+=4){ vis[i] = vis[i+3] = 1; } } for(int i =1;i<=N;i++){ if(s[i] == '1' && vis[i] == 1) printf("3"); if(s[i] == '0' && vis[i] == 1) printf("1"); if(s[i] == '1' && vis[i] == 0) printf("4"); if(s[i] == '0' && vis[i] == 0) printf("2"); } puts(""); return 0; } int main(){ // debug; read(T); while(T--){ read(N); scanf("%s",s+1); solve(); } return 0; }
L
根据公式,(M-i+1)都是正数,且递减,所以单词的喜好度也要是由大到小,这样的结果是最优的
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define debug freopen("in.txt","r",stdin),freopen("out.txt","w",stdout); #define pb push_back #define all(x) x.begin(),x.end() #define fs first #define sc second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; const int maxn = 1e6+10; const int maxM = 1e6+10; const int inf = 0x3f3f3f3f; const ll inf2 = 0x3f3f3f3f3f3f3f3f; template<class T>void read(T &x){ T s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); x = s*w; } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class T>void print(T x){ cout<<x<<" "; } template<class H, class... T> void print(H h, T... t) { print(h); print(t...); } int T,N,M; struct node { string s; int v; bool operator <(const node &o) const{ if(v != o.v) return v > o.v; else return s < o.s; } }arr[maxn]; void solve(){ sort(arr+1,arr+N+1); ll ans = 0; for(int i = 1;i<=M;i++){ ans += 1LL * (M-i+1) * arr[i].v; } cout<<ans<<" "; for(int i = 1;i<=M;i++){ if(i < M) cout<<arr[i].s<<" "; else cout<<arr[i].s<<'\n'; } } int main(){ // debug; ios; cin>>T; while(T--){ cin>>N>>M; for(int i = 1;i<=N;i++){ cin>>arr[i].s>>arr[i].v; } solve(); } return 0; }
M
暴力走一遍即可
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define debug freopen("in.txt","r",stdin),freopen("out.txt","w",stdout); #define pb push_back #define all(x) x.begin(),x.end() #define fs first #define sc second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; const int maxn = 1e6+10; const int maxM = 1e6+10; const int inf = 0x3f3f3f3f; const ll inf2 = 0x3f3f3f3f3f3f3f3f; template<class T>void read(T &x){ T s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); x = s*w; } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class T>void print(T x){ cout<<x<<" "; } template<class H, class... T> void print(H h, T... t) { print(h); print(t...); } int T,N,b; void solve(){ } int main(){ // debug; read(T); while(T--){ read(N,b); bool ok = 0; for(int i = 1;i<=N;i++){ int cur;read(cur); if((cur + b)%7 == 0)ok = 1; } if(ok) puts("Yes"); else puts("No"); } return 0; }