首页 > 代码库 > 2013 ACM/ICPC Asia Regional Chengdu Online

2013 ACM/ICPC Asia Regional Chengdu Online

2013 ACM/ICPC Asia Regional Chengdu Online

题目链接

4730:签到题,直接判断结尾即可
4731:找规律,关键是字母数为2的时候
4734:数位dp,这题把小于和等于的情况分开考虑了,这样每次不用清空dp数组,只需要在计算出等于的情况即可
4737:twopointer+位运算

代码:

#include <cstdio>
#include <cstring>

int t;
char str[105];

int main() {
	int cas = 0;
	scanf("%d", &t);
	while (t--) {
		scanf("%s", str);
		printf("Case #%d: ", ++cas);
		if (strlen(str) < 4) printf("%snanodesu\n", str);
		else {
			int len = strlen(str);
			if (str[len - 1] == 'u' && str[len - 2] == 's' && str[len - 3] == 'e' && str[len - 4] == 'd') {
				for (int i = 0; i < len - 4; i++)
					printf("%c", str[i]);
				printf("nanodesu\n");
			} else {
				printf("%snanodesu\n", str);
			}
		}
	}
	return 0;
}

#include <cstdio>
#include <cstring>

int t;
int n, m;
const char out[10] = "aababb";

int main() {
	int cas = 0;
	scanf("%d", &t);
	while (t--) {
		scanf("%d%d", &m, &n);
		printf("Case #%d: ", ++cas);
		if (m == 1) {
			for (int i = 0; i < n; i++)
				printf("a");
			printf("\n");
		} else if (m == 2) {
			if (n == 1) printf("a\n");
			else if (n == 2) printf("ab\n");
			else if (n == 3) printf("aab\n");
			else if (n == 4) printf("aabb\n");
			else if (n == 5) printf("aaaba\n");
			else if (n == 6) printf("aaabab\n");
			else if (n == 7) printf("aaababb\n");
			else if (n == 8) printf("aaababbb\n");
			else {
				n -= 2;
				printf("aa");
				int ci = n / 6;
				int yu = n % 6;
				for (int i = 0; i < ci; i++)
					printf("%s", out);
				if (yu <= 4) {
					for (int i = 0; i < yu; i++)
						printf("a");
				} else {
					for (int i = 0; i < yu; i++)
						printf("%c", out[i]);
				}
				printf("\n");
			}
		} 
		else {
			int cnt = 0;
			for (int i = 0; i < n; i++) {
				printf("%c", 'a' + cnt);
				cnt = (cnt + 1) % 3;
			}
			printf("\n");
		}
	}
	return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int t, a, b;
int bit[15], pow2[15], n;
int dp[11][10000];

void build() {
	n = 0;
	if (b == 0) bit[n++] = 0;
	while (b) {
		bit[n++] = b % 10;
		b /= 10;
	}
}

int dfs(int u, int s, int flag) {
	if (s < 0) return 0;
	if (u == -1)
		return s >= 0;
	int &ans = dp[u][s];
	if (flag && ans != -1) return ans;
	int tmp = 0;
	if (flag) {
		for (int i = 0; i < 10; i++)
			tmp += dfs(u - 1, s -  i * pow2[u], 1);
	} else {
		for (int i = 0; i < bit[u]; i++)
			tmp += dfs(u - 1, s - i * pow2[u], 1);
		tmp += dfs(u - 1, s - bit[u] * pow2[u], 0);
	}
	if (flag) ans = tmp;
	return tmp;
}

int main() {
	int cas = 0;
	pow2[0] = 1;
	for (int i = 1; i < 10; i++)
		pow2[i] = pow2[i - 1] * 2;
	scanf("%d", &t);
	memset(dp, -1, sizeof(dp));
	while (t--) {
		scanf("%d%d", &a, &b);
		int sum = 0;
		int cn = 0;
		while (a) {
			sum += a % 10 * pow2[cn++];
			a /= 10;
		}
		build();
		printf("Case #%d: %d\n", ++cas, dfs(n - 1, sum, 0));
	}
	return 0;
}

#include <cstdio>
#include <cstring>

const int N = 100005;
int t, n, m, a[32], s[N];
typedef long long ll;

int main() {
	int cas = 0;
	scanf("%d", &t);
	while (t--) {
		ll ans = 0;
		memset(a, 0, sizeof(a));
		scanf("%d%d", &n, &m);
		int l = 0, num;
		for (int i = 0; i < n; i++) {
			scanf("%d", &s[i]);
			int cnt = 0;
			num = s[i];
			while (num) {
				if (num&1)
					a[cnt]++;
				num /= 2;
				cnt++;
			}
			int tmp = 0;
			for (int j = 30; j >= 0; j--)
				tmp = tmp * 2 + (a[j] != 0);
			if (tmp >= m) {
				while (1) {
					num = s[l];
					int cnt = 0;
					while (num) {
						if (num&1)
							a[cnt]--;
						num /= 2;
						cnt++;
					}
					int tmp = 0;
					for (int j = 30; j >= 0; j--)
						tmp = tmp * 2 + (a[j] != 0);
					l++;
					if (tmp < m) {
						ans += (i - l + 1);
						break;
					}
				}
			} else ans += (i - l + 1);
		}
		printf("Case #%d: %I64d\n", ++cas, ans);
	}
	return 0;
}


2013 ACM/ICPC Asia Regional Chengdu Online