高弗雷勋爵
题目链接:https://code.mi.com/problem/list/view?id=113
这个解法比较暴力,主要需要注意的是一颗子弹 弹死两个及以上的情况。
#include <iostream> #include <string> #include <stdio.h> #include <algorithm> #include <vector> using namespace std; ]; void infect(int i, int n) { bool flag = false; for (int j = i; j < n; j++) { //一枪弹死两个的情况 )continue; a[j] -= ; )flag = true; } if (flag) infect(i + , n); } int main() { , res = , t; while (~scanf("%d", &t)) a[n++] = t; sort(a, a + n); ; i < n; i++) { ) { ) { a[i]++; } res += a[i] / ; ; j < n; j++) { a[j] -= a[i]; } } infect(i + , n); ] <= ) i++; } cout << res << endl; ; }
这个比较抽象,不进行减操作,中间用base递增记录下来。(写完才想起来,base开成long long好一点,不过也没爆)
#include <iostream> #include <string> #include <stdio.h> #include <algorithm> #include <vector> using namespace std; ]; ; int main() { , res = , t; while (~scanf("%d", &t)) { )break; a[n++] = t; } sort(a, a + n); ; i < n; i++) { //一枪蹦死两个以上的情况 ) <= ) continue; //只在弹射 弹死的第一个人时,base+=2 ) { ; continue; } ) { a[i]++; } res += (a[i] - ; ; } cout << res << endl; ; }
提交详情
编程语言 | C++11 - G++ 6.4.0 | 结果 | 通过 |
---|---|---|---|
最大执行时间 | 2.81 ms | 最大内存开销 | 4136 KiB |
判题信息 |
运行时间打败了 94.3% 的 C++ 玩家! |