Div2.A
#include <stdio.h> int a[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; int main() { int n , m , now = 1; scanf("%d%d",&n,&m); for(int i=1; i<a[n]; ++i) { ++m; if(m > 7) m -= 7 , ++now; }printf("%d\n",now); }
Div2.B
#include <stdio.h> #include <iostream> using std::max; int n , m , k; bool check(int mid) { long long l = k-mid+1 , r = k+mid-1; long long sum = 1+mid; sum *= mid; sum -= mid; if(l < 1) { l = -l + 1; l = (1+l) * l / 2; sum -= l; } if(r > n) { r -= n; r = (1+r) * r / 2; sum -= r; } return sum <= m-n; } int main() { scanf("%d%d%d",&n,&m,&k); int l = 0 , r = m-n , ans = 0; while(l <= r) { int mid = (l + r) >> 1; if(check(mid)) ans = mid , l = mid + 1; else r = mid - 1; }printf("%d\n",ans+1); }
A.
#include <stdio.h> inline int F() { register int aa , bb , ch; while(ch = getchar() , (ch<'0'||ch>'9') && ch != '-'); ch == '-' ? aa=bb=0 : (aa=ch-'0',bb=1); while(ch = getchar() , ch>='0'&&ch<='9') aa = aa*10 + ch-'0'; return bb ? aa : -aa; } const int Maxn = 200005; int n , sum , cnt , to[Maxn]; bool vis[Maxn]; int main() { n = F(); for(int i=1; i<=n; ++i) to[i] = F(); for(int i=1; i<=n; ++i) sum += F(); for(int i=1; i<=n; ++i) if(!vis[i]) { ++cnt; while(!vis[i]) vis[i] = 1 , i = to[i]; } printf("%d\n",(~sum&1)+(cnt == 1 ? 0 : cnt)); }
B.
#include <stdio.h> inline int min(const int&a , const int&b) { return a < b ? a : b; } inline int F() { register int aa , bb , ch; while(ch = getchar() , (ch<'0'||ch>'9') && ch != '-'); ch == '-' ? aa=bb=0 : (aa=ch-'0',bb=1); while(ch = getchar() , ch>='0'&&ch<='9') aa = aa*10 + ch-'0'; return bb ? aa : -aa; } const int Maxn = 100010; int n , a[Maxn] , f[Maxn]; int find(int n , int t) { int l = 1 , r = n , mid , ans = n; while(l <= r) { mid = (l + r) >> 1; if(a[mid]>a[n]-t) r = mid - 1 , ans = mid; else l = mid + 1; } return ans-1; } int main() { n = F(); for(int i=1; i<=n; ++i) { a[i] = F(); f[i] = min(f[i-1]+20 , min(f[find(i,90)]+50 , f[find(i,1440)]+120)); } for(int i=1; i<=n; ++i) printf("%d\n",f[i]-f[i-1]); }
C.比较有意思
#include <stdio.h> #define min(a,b) ((a) < (b) ? (a) : (b)) #define max(a,b) ((a) > (b) ? (a) : (b)) inline int F() { register int aa , bb , ch; while(ch = getchar() , (ch<'0'||ch>'9') && ch != '-'); ch == '-' ? aa=bb=0 : (aa=ch-'0',bb=1); while(ch = getchar() , ch>='0'&&ch<='9') aa = aa*10 + ch-'0'; return bb ? aa : -aa; } const int Maxn = 100005; const int Maxt = 4*Maxn; int n , ans[Maxn] , mx[Maxt] , ll[Maxt] , rr[Maxt] , lazy[Maxt]; void update(int x) { if(ll[x] == rr[x]) return; mx[x] = max(mx[x<<1], mx[x<<1|1]); } void downpush(int x) { if(ll[x] == rr[x]) return; mx[x<<1] += lazy[x]; lazy[x<<1] += lazy[x]; mx[x<<1|1] += lazy[x]; lazy[x<<1|1] += lazy[x]; lazy[x] = 0; } void Build(int x , int l , int r) { ll[x] = l; rr[x] = r; if(l == r) return; int mid = (l + r) >> 1; Build(x<<1 , l , mid); Build(x<<1|1 , mid+1 , r); } void modify(int x , int l , int r , int val) { downpush(x); l = max(ll[x] , l); r = min(rr[x] , r); if(l > r) return; if(l == ll[x] && r == rr[x]) { mx[x] += val; lazy[x] += val; } else modify(x<<1 , l , r , val) , modify(x<<1|1 , l , r , val) , update(x); } int find(int x) { downpush(x); if(ll[x] == rr[x]) return ll[x]; if(mx[x<<1|1] > 0) return find(x<<1|1); else return find(x<<1); } int main() { n = F(); Build(1,1,n); for(int i=1; i<=n; ++i) { int x = F() , op = F(); if(!op) modify(1,1,x,-1); else { int val = F(); ans[x] = val; modify(1,1,x,1); } if(mx[1] > 0) printf("%d\n",ans[find(1)]); else puts("-1"); } }
后面三题什么鬼玩意?