AtCoder Beginner Contest 104

SMU某ACM集训队选手经过一年训练,打了场ABC,掉了71分

心态也是一种实力,这句话没错

ABC 104

A:不谈

B:让我们来好好阅读一下这句话

  • There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).

来看一下一号选手Google tanslate的表现:

在从开头到第三个字符和从第二个到最后一个字符(包括)之间恰好出现一次C.

再看一下二号选手有道翻译的表现:

在第三个字符从开始和第二个到最后一个字符(包括)之间,有一个C的出现。

最后看看三号选手百度翻译的表现:

从开始的第三个字符和第二个到最后一个字符(包含)之间恰好有一个C的出现。

好了,都是错的。

最后再看一下一位不愿意透露姓名的英语六级选手的表现(正解)

在 从头开始的第三个字符 到 从最后开始的第二个字符 之间,恰好有一个‘C’出现(包含端点)

再转换成标准点的中文描述:正着数第三个数到倒着数第二个数之间,有且仅有一个'C'

下面是一位愿意透露姓名的英语四级都没过的选手的英文表达:for every s[i], (i >= 3 && i <= |s| - 2), there is exactly one occurrence of 'C'

好了,皮完了,就是想吐槽一下出题人

读懂了也是水题,不谈

C:

思路:注意到D比较小,状压枚举选哪几道题即可

AC Code:

#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
using namespace std;

int p[11], c[11];

int main()
{
	int D, G; scanf("%d %d", &D, &G);
	for(int i = 0; i < D; i++) scanf("%d %d", p + i, c + i);
	int ans = inf;
	for(int i = 0; i < (1 << D); i++){
		ll sum = 0;
		int cnt = 0;
		for(int j = 0; j < D; j++){
			if((i >> j) & 1){
				sum += p[j] * (j + 1) * 100 + c[j];
				cnt += p[j];
			}
		}
		for(int j = D - 1; j >= 0; j--){
			if((i >> j) & 1) continue;
			if(sum >= G) continue;
			int q = min((G - sum)/((j + 1) * 100), (ll)p[j]);
			cnt += q;
			sum += (j + 1) * 100 * q;
		}
		if(G <= sum) ans = min(ans, cnt);
	}
	printf("%d\n", ans);
	return 0;
}

D:

动态规划解决

这个dp还是挺好理解的,对于每一个位置求出贡献即可

#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)5;
using namespace std;

ll dp[maxn][5];
 
int main()
{
	string s; cin >> s;
	int n = s.size();
	dp[n][3] = 1, dp[n][0] = dp[n][1] = dp[n][2] = 0;
	for(int i = n - 1; i >= 0; i--){
		for(int j = 3; j >= 0; j--){
			dp[i][j] = dp[i+1][j] * (s[i] == '?' ? 3 : 1);
			if(j < 3 && (s[i] == '?' || s[i] == "ABC"[j])){
				dp[i][j] += dp[i+1][j+1];
			}
			dp[i][j] %= mod;
		}
	}
	printf("%lld\n", dp[0][0]);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/swunHJ/article/details/81458658