本文共 1830 字,大约阅读时间需要 6 分钟。
#include #include #include #include #include #include #include #include #include #include #include #include #define MM(a) memset(a,0,sizeof(a)) typedef long long ll; typedef unsigned long long ULL; const int mod = 1000000007; const int inf = 0x3f3f3f3f; using namespace std; int a1[25], a2[25]; int solve() { int ans1= 0,ans2=0; memcpy(a2, a1, sizeof(a1)); for (int i = 2; i <= 20;i++) if (a1[i - 1] % 2 == 1) { a1[i]++; a1[i + 1]++; ans1++; } if (a1[20] % 2 == 1) ans1 = inf; ans2++; a2[1] = 1 - a2[1]; a2[2] = 1 - a2[2]; for (int i = 2; i <= 20;i++) if (a2[i-1]%2==1) { a2[i]++; a2[i + 1]++; ans2++; } if (a2[20] % 2 == 1) ans2 = inf; return ans1 < ans2 ? ans1: ans2; } int main() { memset(a1, 0, sizeof(a1)); memset(a2, 0, sizeof(a2)); while (~scanf("%d",&a1[1])) { for (int i = 2; i <= 20; i++) scanf("%d", &a1[i]); printf("%d\n", solve()); } return 0; }
#include #include #include #include #include #include #include #include #include #include #include #include #define MM(a) memset(a,0,sizeof(a)) typedef long long ll; typedef unsigned long long ULL; const int mod = 1000000007; const int inf = 0x3f3f3f3f; using namespace std; int a[25],f[25]; int solve() { int ans = 0; memset(f, 0, sizeof(f)); for (int i = 1; i <= 18;i++) if ((a[i] + f[i]) % 2 == 1) { f[i + 1]++; f[i + 2]++; ans++; } if ((a[19] + f[19]) % 2 == 1) ans++; return ans; } int main() { for (int i = 1; i <= 20; i++) scanf("%d", &a[i]); printf("%d\n", solve()); return 0; }
转载地址:http://vvgsi.baihongyu.com/