高弗雷勋爵
题目链接:https://code.mi.com/problem/list/view?id=113
这个解法比较暴力,主要需要注意的是一颗子弹 弹死两个及以上的情况。
#include <iostream> #include <string> #include <stdio.h> #include <algorithm> #include <vector> using namespace std; int a[10001]; void infect(int i, int n) { bool flag = false; for (int j = i; j < n; j ) { //一枪弹死两个的情况 if (a[j] <= 0)continue; a[j] -= 2; if (a[j] <= 0)flag = true; } if (flag) infect(i 1, n); } int main() { int n = 0, res = 0, t; while (~scanf("%d", &t)) a[n ] = t; sort(a, a n); for (int i = 0; i < n; i ) { if (a[i] > 0) { if (a[i] % 2) { a[i] ; } res = a[i] / 2; for (int j = i 1; j < n; j ) { a[j] -= a[i]; } } infect(i 1, n); while (i < n&&a[i 1] <= 0) i ; } cout << res << endl; return 0; }View Code
这个比较抽象,不进行减操作,中间用base递增记录下来。(写完才想起来,base开成long long好一点,不过也没爆)
#include <iostream> #include <string> #include <stdio.h> #include <algorithm> #include <vector> using namespace std; int a[10001]; int base = 0; int main() { int n = 0, res = 0, t; while (~scanf("%d", &t)) { if (t == 0)break; a[n ] = t; } sort(a, a n); for (int i = 0; i < n; i ) { //一枪蹦死两个以上的情况 if (a[i] - (base - 2) <= 0) continue; //只在弹射 弹死的第一个人时,base =2 if (a[i] - base <= 0) { base = 2; continue; } if (a[i] % 2) { a[i] ; } res = (a[i] - base) / 2; base = (a[i] - base) 2; } cout << res << endl; return 0; }View Code