HDU 5835 Danganronpa

来源:互联网 发布:林彪为什么叛变 知乎 编辑:程序博客网 时间:2024/05/16 08:11

...神特么弹丸论破

有n种礼物,每种礼物a[I]个,现在有一排无限长的桌子,要往上面放礼物,每个桌子放两个礼物,第一个礼物要求相邻的桌子第一个礼物是不同的,第二个礼物没有这个要求,可以随便选一种礼物放,要求放礼物要相邻,不能隔着一个空桌子,问最多能放多少个桌子。

我的做法类似模拟,看能多出多少个,如果多出很多的话,那最后答案就是能凑成相邻不重复串的长度,如果多出来的不多,凑完相邻不重复子串没啥剩下的了,那最后答案就是剩下的。水题,数据也水....

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[10];int r[10];int n;int x = 0;int y = 0;int ans;long long sum;int main(void){int T;int cas = 1;cin >> T;while (T--){memset(r, 0, sizeof r);x = y = sum = 0;cin >> n;for (int i = 0; i < n; i++){cin >> a[i];sum += a[i];}sort(a, a + n);for (int i = n - 1; i >= 1; i--){if (a[i] <= a[i - 1] + 1) continue;r[i] = a[i] - a[i - 1] - 1;a[i] = a[i - 1] + 1;}for (int i = 0; i < n; i++) x += a[i];for (int i = 1; i < n; i++) y += r[i];if (y > x) ans = x;else ans = sum / 2;if (n == 1) ans = 1;cout << "Case #" << cas++ << ": " << ans << endl;}return 0;}

0 0
原创粉丝点击