嵐圖汽車中大型智慧電動SUV完成高溫高原嚴苛測試
阿新 • • 發佈:2020-10-22
Codeforces Round #676 (Div. 2)
A
考慮貪心:兩個1顯然填,兩個0顯然不用,一1一0隨便。
#include<iostream> #include<cstdio> using namespace std; int a, b; int main() { int x, T; scanf("%d", &T); while(T --) { scanf("%d %d", &a, &b); x = a & b; printf("%lld\n", (a ^ x) + (b ^ x)); } return 0; }
B
最簡便的方法其實就是把住兩個角。
分類 細節題。
#include<iostream> #include<cstdio> using namespace std; const int N = 200 + 5; int n; char map[N][N]; int main() { int T; scanf("%d", &T); while(T --) { scanf("%d", &n); for(int i = 0; i < n; ++ i) scanf("%s", map[i]); int cnt = 0; if(map[0][1] == '1') ++ cnt; if(map[1][0] == '1') ++ cnt; if(map[n - 1][n - 2] == '1') ++ cnt; if(map[n - 2][n - 1] == '1') ++ cnt; if(cnt == 0 || cnt == 4) { printf("2\n"); printf("%d %d\n%d %d\n", 1, 2, 2, 1); } else { if(cnt == 2) { if(map[0][1] != map[1][0]) { printf("2\n"); if(map[0][1] == '0') printf("%d %d\n", 1, 2); else printf("%d %d\n", 2, 1); if(map[n - 1][n - 2] == '1') printf("%d %d\n", n, n - 1); else printf("%d %d\n", n - 1, n); } else puts("0"); } else { if(cnt == 1) { printf("1\n"); if(map[0][1] == '1') printf("%d %d\n", 2, 1); if(map[1][0] == '1') printf("%d %d\n", 1, 2); if(map[n - 1][n - 2] == '1') printf("%d %d\n", n - 1, n); if(map[n - 2][n - 1] == '1') printf("%d %d\n", n, n - 1); } else { printf("1\n"); if(map[0][1] == '0') printf("%d %d\n", 2, 1); if(map[1][0] == '0') printf("%d %d\n", 1, 2); if(map[n - 1][n - 2] == '0') printf("%d %d\n", n - 1, n); if(map[n - 2][n - 1] == '0') pritf("%d %d\n", n, n - 1); } } } } return 0; }
C
構造有點奇妙,首先發現一旦中間出現迴文串(奇數)就可以通過操作完成。
#include<iostream> #include<string> #include<cstdio> #include<cmath> using namespace std; const int SIZE = 1e5 + 5; string s; int n; int main() { getline(cin, s); n = s.size(); printf("%d\n", 5); printf("L %d\n", n - 1); puts("L 2"); printf("R %d\n", n + 1); printf("L %d\n", n * 2 - 1); printf("L %d\n", n - 1); return 0; }
D
真是一道送的題目,貪心+分類討論細節題
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
long long x, y, c[7];
int main()
{
int t;
scanf("%d", &t);
while(t --)
{
scanf("%lld %lld", &x, &y);
long long ans;
for(int i = 1; i <= 6; ++ i) scanf("%lld", &c[i]);
if(x * y >= 0)
{
if(x <= 0 && y <= 0)
{
x = -x, y = -y;
for(int i = 1; i <= 3; ++ i) swap(c[i], c[i + 3]);
}
if(x > y)
{
swap(x, y), swap(c[2], c[6]), swap(c[3], c[5]);
}
ans = min(c[6] * x + c[2] * y, min(c[1] * x + c[2] * (y - x), c[3] * (y - x) + c[1] * y));
printf("%lld\n", ans);
}
else
{
if(x < 0) x = -x;
else
{
y = -y;
for(int i = 1; i <= 3; ++ i) swap(c[i], c[i + 3]);
}
ans = c[3] * x + c[2] * y;
if(c[1] + c[3] < c[2]) ans = min(ans, c[3] * x + (c[1] + c[3]) * y);
if(c[2] + c[4] < c[3]) ans = min(ans, (c[2] + c[4]) * x + c[2] * y);
printf("%lld\n", ans);
}
}
return 0;
}