程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces Round #268 (Div. 2)

Codeforces Round #268 (Div. 2)

編輯:C++入門知識

Codeforces Round #268 (Div. 2)


Codeforces Round #268 (Div. 2)

題目鏈接

A:有的標記掉判斷一下即可

B:枚舉時間一個個去判斷一下即可

C:構造一下,4和5分別手動構造,然後之後每次多2個數字就先相減掉得到1,然後乘上原數字不變,4以下的是絕對構造不出來的

D:貪心,先排序,然後每次twopointer選頭尾兩個判斷能丟進哪個集合,都不行就找一個之前滿足的丟進小集合

E:推理,詳細見官方題解,大致是推出來後,[x, x + 1e18 - 1]這個區間,每次挪動一個變成[x + 1, x + 1e18],對應的總和就加1,那麼只要能求出[1, 1e18]的值,然後在去挪動相應步數得到相應區間即可,計算1-1e18的和推推規律就可以發現了,官方題解上也有公式

代碼:

A:

#include 
#include 

int n, p, q, vis[105];

bool solve() {
	for (int i = 1; i <= n; i++)
		if (vis[i] == 0) return false;
	return true;
}

int main() {
	scanf("%d", &n);
	scanf("%d", &p);
	int tmp;
	for (int i = 0; i < p; i++) {
		scanf("%d", &tmp);
		vis[tmp] = 1;
	}
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d", &tmp);
		vis[tmp] = 1;
	}
	printf("%s\n", solve() ? "I become the guy." : "Oh, my keyboard!");
	return 0;
}

B:

#include 
#include 

const int N = 55;

int p, q, l, r, ans;
int vis[10005], c[N], d[N];

bool judge(int t) {
	for (int i = 0; i < q; i++) {
		for (int j = c[i]; j <= d[i]; j++) {
			if (vis[j + t])
				return true;
		}
	}
	return false;
}

int main() {
	scanf("%d%d%d%d", &p, &q, &l, &r);
	int a, b;
	for (int i = 0; i < p; i++) {
		scanf("%d%d", &a, &b);
		for (int j = a; j <= b; j++)
			vis[j] = 1;
	}
	for (int i = 0; i < q; i++)
		scanf("%d%d", &c[i], &d[i]);
	for (int i = l; i <= r; i++) {
		if (judge(i)) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

C:

#include 
#include 
#include 
#include 
using namespace std;

int n;

void solve(int n) {
	if (n % 2 == 0) {
		printf("1 + 2 = 3\n");
		printf("3 + 3 = 6\n");
		printf("6 * 4 = 24\n");
		for (int i = 5; i <= n; i += 2) {
			printf("%d - %d = 1\n", i + 1, i);
			printf("24 * 1 = 24\n");
		}
	} else {
		printf("5 - 3 = 2\n");
		printf("1 + 2 = 3\n");
		printf("2 * 3 = 6\n");
		printf("4 * 6 = 24\n");
		for (int i = 6; i <= n; i += 2) {
			printf("%d - %d = 1\n", i + 1, i);
			printf("24 * 1 = 24\n");
		}
	}
}

int main() {
	scanf("%d", &n);
	if (n < 4) printf("NO\n");
	else {
		printf("YES\n");
		solve(n);
	}
	return 0;
}

D:

#include 
#include 
#include 
#include 
using namespace std;

const int N = 100005;

int n, a, b;
map to;

struct Seq {
	int num, id, to, vis;
} s[N];

bool cmp(Seq a, Seq b) {
	return a.num < b.num;
}

bool cmpid(Seq a, Seq b) {
	return a.id < b.id;
}

int flag = 0;

bool solve() {
	int st = 0, ed = n - 1;
	while (st <= ed) {
		if (s[st].vis) {
			st++;
			continue;
		}
		if (s[ed].vis) {
			ed--;
			continue;
		}
		if (s[st].num + s[ed].num > b || s[st].num + s[ed].num < a)
			return false;
		if (s[st].num + s[ed].num == b) {
			s[st].vis = 1;
			s[ed].vis = 1;
			s[st].to = 1;
			s[ed].to = 1;
			st++;
			ed--;
			continue;
		} else if (s[st].num + s[ed].num == a) {
			s[st].vis = 0;
			s[ed].vis = 0;
			s[st].to = 0;
			s[ed].to = 0;
			st++;
			ed--;
		} else {
			if (!to.count(a - s[st].num)) return false;
			int v = to[a - s[st].num];
			if (s[v].vis) return false;
			s[v].to = 0;
			s[v].vis = 1;
			s[st].vis = 1;
			s[st].to = 0;
			st++;
		}
	}
	sort(s, s + n, cmpid);
	printf("YES\n");
	printf("%d", s[0].to^flag);
	for (int i = 1; i < n; i++)
		printf(" %d", s[i].to^flag);
	printf("\n");
	return true;
}

int main() {
	scanf("%d%d%d", &n, &a, &b);
	if (a > b) {
		swap(a, b);
		flag = 1;
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &s[i].num);
		s[i].id = i;
	}
	sort(s, s + n, cmp);
	for (int i = 0; i < n; i++)
		to[s[i].num] = i;
	if (!solve()) printf("NO\n");
	return 0;
}

E:

#include 
#include 
#include 
using namespace std;

typedef long long ll;
const ll INF = 1e18;

ll a;

int main() {
	scanf("%lld", &a);
	ll num = INF / 10 % a;
	num = num * 2 % a;
	num = num * 9 % a;
	num = num * 9 % a;
	num = num * 5 % a;
	printf("%lld %lld\n", a - num, a - num + INF - 1);
	return 0;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved