Codeforces Round #381 (Div. 2)
来源:互联网 发布:怎么查看知乎提问者 编辑:程序博客网 时间:2024/05/21 10:29
这次比赛,两个队友一起在机房做,还叫了外卖来机房,边喝啤酒边吃烧烤边做题,很爽。
——
第一题:
你有N个东西
买一个东西要花 A元钱
两个要B
三个要C
问至少花多少钱把东西凑成4的倍数
——
一开始想的是先把最便宜的找到,也就是6A 3B 2C那个小,按顺序买
不过下去拿烧烤的时候我们讨论了一下,发现这样想法不对
比如说买2个可能比买6个贵
——
于是我想用完全背包找个最小的,不过不知道范围。
又一个队友说,其实就是多考虑几种情况就好了。
于是我就找了12以下的最优解。
AC
——
第二题:
超水,就是一个前缀和,不说了
——
第三题:
一开始看不懂,百度了还是看不懂,后来一个队友说看题就好了,然后就看懂了。
题目说mex()函数
这个函数是什么鬼?本来想matlab help一下的,结果是另外的东西。
第二天我一看书,发现我原来是知道的,就是Nim游戏里面需要的那个函数。不过我早就忘了。
现在再来说下mex函数是什么
就是一个集合,从0开始1 2 3第一个没出现的正整数,就是mex函数的值
题目首先输入n, m
表示n个数 m个区间
构造一个数列,使这m个区间里 mex函数最小的那个最大
只需要构造一个数列就好
i.e. special judge的题
——
现在问题来了,任意一个集合的mex值最大是多少?
size() + 1
那么ans会不是min(r - l) + 1呢?
应该是,只需要把 l ~ r 区间填上 0 ~ (r - l)就好了
然后别的区间怎么构造呢?
比赛的时候就没想到了。
想到了一个,还是WA了。我还交了两发。
然后比赛就结束了。
CF一个好处就是可以看所有人的代码和测试数据。
然后我一看一个?
怎么TM的这么短?
假设ans是3
直接
0 1 2 0 1 2 0 1 2就好了
怎么证明呢?
显然任意一端区间的长度都是大于等于ans - 1
然后这里面所有大于ans的区间都只有 0 1 2 Mex = 3
证毕。
——
这次还是负分 尬尴
第一题:
#define LOG(x) cout << #x << " = " << (x) << endl#define PRINTLN(x) cout << (x) << endl#define MEM(x, y) memset((x), (y), sizeof((x)))#include <bits/stdc++.h>using namespace std;const double PI = 2*acos(0);typedef long long ll;typedef complex<double> Complex;typedef pair<ll, int> P;int nextInt(){ int x; scanf("%d", &x); return x;}ll nextLL(){ ll x; scanf("%lld", &x); return x;}//TEMPLATE//MAINll n;void solve(){ ll a[3]; for (int i = 0; i < 3; i++) { a[i] = nextLL(); } ll dp[13]; MEM(dp, -1); dp[0] = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j <= 12 - (i + 1); j++) { if (dp[j + (i + 1)] == -1) dp[j + (i + 1)] = a[i] + dp[j]; else dp[j + (i + 1)] = min(dp[j + (i + 1)], dp[j] + a[i]); } } if (n % 4 == 0) { cout << 0 << endl; return; } int s = 4 - n % 4; ll ans = min(dp[s], min(dp[s + 4], dp[s + 8])); cout << ans << endl;}int main(){ //freopen("in.txt", "r", stdin); while (scanf("%lld", &n) != EOF) { solve(); }}
第二题
#define LOG(x) cout << #x << " = " << (x) << endl#define PRINTLN(x) cout << (x) << endl#define MEM(x, y) memset((x), (y), sizeof((x)))#include <bits/stdc++.h>using namespace std;const double PI = 2*acos(0);typedef long long ll;typedef complex<double> Complex;int nextInt(){ int x; scanf("%d", &x); return x;}ll nextLL(){ ll x; scanf("%lld", &x); return x;}//TEMPLATE//MAINconst int MAXN = 1000;int a[MAXN], s[MAXN];int main(){ //freopen("in.txt", "r", stdin); int n, m; while (scanf("%d%d", &n, &m) != EOF) { MEM(a, 0); MEM(s, 0); for (int i = 1; i <= n; i++) { a[i] = nextInt(); } for (int i = 1; i <= n; i++) { s[i] = s[i - 1] + a[i]; } ll ans = 0; for (int i = 0; i < m; i++) { int l = nextInt(), r = nextInt(); ans += (s[r] - s[l - 1] > 0 ? s[r] - s[l - 1] : 0); } cout << ans << endl; }}
第三题
#define LOG(x) cout << #x << " = " << (x) << endl#define PRINTLN(x) cout << (x) << endl#define MEM(x, y) memset((x), (y), sizeof((x)))#include <bits/stdc++.h>using namespace std;const double PI = 2*acos(0);const int INF = INT_MAX;typedef long long ll;typedef complex<double> Complex;int nextInt(){ int x; scanf("%d", &x); return x;}ll nextLL(){ ll x; scanf("%lld", &x); return x;}//TEMPLATE//MAINint main(){ //freopen("in.txt", "r", stdin); int n = nextInt(), m = nextInt(); int ans = INF; for (int i = 0; i < m; i++) { int l = nextInt(), r = nextInt(); ans = min(ans, r - l); } ans++; cout << ans << endl; cout << 0; for (int i = 1; i < n; i++) { cout << ' ' << i % ans; } cout << endl;}
- Codeforces Round #381 (Div. 2)
- Codeforces Round #381 (Div. 2)
- Codeforces Round #381 (Div. 2)
- Codeforces Round #381 (Div. 2) &&Codeforce_740
- Codeforces Round #381 (Div. 2) #V
- Codeforces Round #381 (Div. 1)
- Codeforces Round #381 (Div. 1)
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Codeforces Round #122 (Div. 2)
- Codeforces Round #121 (Div. 2)
- 测试例:子游标个数限定的功能使用例
- Codeforces 682C Alyona and the Tree【Dfs+YY思维】好题
- 即刻起航
- css布局之爱上flex
- PS千图成像
- Codeforces Round #381 (Div. 2)
- sqlalchemy 中filter和filter_by区别
- tensorflow -----细枝末节
- 使用diskpart恢复使用win32 disk imager处理过的U盘
- JSON.NET中文乱码解决。
- Matlab textread 函数详解
- 湘潭大学 操作系统 调度算法 FCFS SSTF SCAN SJF OPT LRU
- Html基础知识总结
- java web 连接mysql数据库