2
13
2017
0

CF Round #350

A.

 

#include <stdio.h>
int main() {
	int n;
	scanf("%d",&n);
	if(n<3) { printf("0 %d",n); return 0; }
	int tmp = n%7 , ans1 = (n/7)*2;
	if(tmp == 6) ++ans1;
	int ans2 = 2; n-=2;
	tmp = n%7; ans2 += (n/7)*2;
	if(tmp == 6) ++ans2;
	printf("%d %d\n",ans1,ans2);
}

B.

 

#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 = 100005;
int n , k , a[Maxn]; long long s = 0;
int main() {
	n = F() , k = F();
	for(int i=1; i<=n; ++i) a[i] = F();
	for(int i=1; i<=n; ++i) {
		++s;
		if(s >= k) {
			printf("%d\n",a[k]);
			return 0;
		} else k -= s;
	}
}

C.

 

#include <stdio.h>
#include <algorithm>
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 , m , cnt , a[Maxn] , b[Maxn] , s[Maxn] , c[Maxn] , d[Maxn] , ans = 1;
int find(int x) {
	int l = 1 , r = cnt , mid;
	while(l <= r) {
		mid = (l + r) >> 1;
		if(b[mid] == x) return mid;
		if(b[mid] > x) r = mid - 1;
		else l = mid + 1;
	} return 0;
}
int main() {
	n = F();
	for(int i=1; i<=n; ++i) b[i] = a[i] = F();
	std::sort(b+1,b+n+1); cnt = 1;
	for(int i=2; i<=n; ++i) if(b[i] != b[cnt]) b[++cnt] = b[i];
	for(int i=1; i<=n; ++i) ++s[find(a[i])];
	m = F();
	for(int i=1; i<=m; ++i) c[i] = s[find(F())];
	for(int i=1; i<=m; ++i) {
		d[i] = s[find(F())];
		if(c[i] > c[ans] || (c[i] == c[ans] && d[i] > d[ans])) ans = i;
	} printf("%d\n",ans);
}

D2.

 

#include <stdio.h>
#define max(a,b) ((a) > (b) ? (a) : (b))
#define inf 2e9
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 , k , a[Maxn] , b[Maxn];
bool check(unsigned int x) {
	int tmp = k;
	for(int i=1; i<=n; ++i) {
		long long used = 1ll * x * a[i] - b[i];
		if(tmp >= used) {
			if(used >= 0) tmp -= used;
		} else return 0;
	} return 1;
}
int main() {
	n = F() , k = F();
	for(int i=1; i<=n; ++i) a[i] = F();
	for(int i=1; i<=n; ++i) b[i] = F();
	unsigned int l = 0 , r = inf , mid , ans;
	while(l <= r) {
		mid = (l + r) >> 1;
		if(check(mid)) ans = mid , l = mid + 1;
		else r = mid - 1;
	} printf("%d\n",ans);
}

E.

 

#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 = 500005;
int n , m , p , ch , a[Maxn] , fal[Maxn] , far[Maxn];
int findl(int x) { return fal[x] == x ? x : fal[x] = findl(fal[x]); }
int findr(int x) { return far[x] == x ? x : far[x] = findr(far[x]); }
int main() {
	n = F() , m = F() , p = F();
	for(int i=1; i<=n; ++i) {
		fal[i] = far[i] = i;
		while(ch = getchar() , ch!='(' && ch!=')');
		if(ch == '(') a[i] = -1;
		else a[i] = 1;
	}
	far[n+1] = fal[n+1] = n+1;
	far[n+2] = fal[n+2] = n+2;
	while(m--) {
		while(ch = getchar() , ch!='L' && ch!='R' && ch!='D');
		if(ch == 'L') { p = findl(p-1); }
		if(ch == 'R') { p = findr(p+1); }
		if(ch == 'D') {
			if(a[p] == 1) {
				int now = 0;
				while(1) {
					now += a[p];
					fal[p] = p-1;
					far[p] = p+1;
					if(now == 0) {
						if(findr(p) <= n) p = findr(p);
						else if(findl(p) >= 1) p = findl(p);
						else return 0;
						break;
					}p = findl(p);
				}
			}
			else {
				int now = 0;
				while(1) {
					now += a[p];
					fal[p] = p-1;
					far[p] = p+1;
					if(now == 0) {
						if(findr(p) <= n) p = findr(p);
						else if(findl(p) >= 1) p = findl(p);
						else return 0;
						break;
					}p = findr(p);
				}
			}
		}
	}
	int now = 1;
	while(now <= n) {
		int x = findr(now);
		if(x <= n) {
			if(a[x] == -1) putchar('(');
			else putchar(')');
		}
		now = x+1;
	}
}

F.

 

#include <stdio.h>
#include <string>
#include <string.h>
#include <iostream>
using namespace std;
const int Maxn = 1000005;
int n , len , cnt[100] , ch; char s[Maxn];
string s1 , s2 , s3;
void Init() {
	while(ch = getchar() , ch < '0' || ch > '9'); ++cnt[ch-'0']; n = 1;
	while(ch = getchar() ,ch >= '0' && ch <= '9') ++cnt[ch-'0'] , ++n ;
	scanf("%s",s+1);
}
int bit(int x){
	int ans = 0;
	while(x) x/=10 , ++ans;
	return ans;
}
void getlen() {
	int len = n;
	while(bit(len) != n-len) --len;
	int tmp = n = len;
	while(tmp) --cnt[tmp%10] , tmp/=10;
	len = strlen(s+1);
	for(int i=1; i<=len; ++i) {
		--cnt[s[i]-'0']; --n;
	}
}
int main() {
	Init();
	getlen();
	if(n == 0) {
		printf("%s",s+1);
	} else if(s[1] == '0') {
		int flag;
		for(int i=1; i<=9; ++i) {
			if(cnt[i]) {
				flag = i; break;
			}
		}
		printf("%d",flag); --cnt[flag];
		while(cnt[0]--) printf("0"); printf("%s",s+1);
		for(int i=1; i<=9; ++i) while(cnt[i]--) printf("%d",i);
	}
	else {
		int flag = 0;
		for(int i=1; i<=9; ++i) {
			if(cnt[i]) {
				flag = i; break;
			}
		}
		if(!flag) {
			printf("%s",s+1); while(cnt[0]--) printf("0"); return 0;
		}
		else if(flag > s[1]-'0') {
			printf("%s",s+1);
			for(int i=0; i<=9; ++i) while(cnt[i]--) printf("%d",i);
		}
		else {
			s1 += s+1;
			for(int i=0; i<=9; ++i) {
				int tmp = cnt[i];
				while(tmp--) s1 += i+'0';
			}
			s2 += flag+'0'; s3 += flag+'0';
			--cnt[flag];
			for(int i=0; i<s[1]-'0'; ++i) {
				while(cnt[i]--) {
					s2 += i+'0';
					s3 += i+'0';
				}
			}
			s2 += s+1;
			while(cnt[s[1]-'0']--) {
				s2 += s[1];
				s3 += s[1];
			}
			s3 += s+1;
			for(int i=s[1]-'0'+1; i<10; ++i) {
				while(cnt[i]--) {
					s2 += i+'0';
					s3 += i+'0';
				}
			}
			if(s1 > s2) {
				if(s2 > s3) cout<<s3;
				else cout<<s2;
			}
			else {
				if(s1 > s3) cout<<s3;
				else cout<<s1;
			}
		}
	}
}
Category: Codeforces | Tags: | Read Count: 1221

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com