cfER 609div2
A Equation standard input/output 3 s, 256 MB Submit Add to favourites x8521
手推一下, 把 1 2 单独输出, 其他奇数输出 3*n 2*n 偶数则输出 4*n 2*n
B Modulo Equality standard input/output 3 s, 256 MB Submit Add to favourites x4481
枚举一下 (b[0]-a[i]+m)%m 将可能的答案储存,输出最小的答案, O(n*n log n)
C Long Beautiful Integer standard input/output 3 s, 256 MB Submit Add to favourites x3037
想半天,写了个假算法 一小时后就被hack了,-_-!, 当字符串 s 满足 beautiful 时 直接输出, 否则就重写一个字符串 i < k时 t[i] = s[i] , i >= k t[i] = t[i-k], 然后比较大小 如果 t > s, 直接输出, 否则还需要再修改一下 t 让它的值更大, 当 s[i] (i k-1~0) 小于 9 时 直接 s[i]+=1 之后的 s[i+=k]+=1 , 否则 有数位为9 则置为0, 代码如下
D Domino for Young standard input/output 3 s, 256 MB Submit Add to favourites x1672
用双色染色法,用黑白二色将图形染色 黑白相邻 会发现 无论1*2的domino 如何放置 都会经过一黑一白 所以计算黑白格子的最小数量即可
如果不太了解可以戳这里 或者直接搜索染色法和构造法在棋盘上的应用
E K Integers standard input/output 3 s, 256 MB Submit Add to favourites x188
过的人蛮少, 不想看
#include <bits/stdc++.h>//cfER 609div2 using namespace std; #define ll long long #define _for(i,a,b) for(int i = (a); i < (b); i++) #define _rep(i,a,b) for(int i = (a); i <= (b); i++)
void taskA1(){ ll n; cin >> n; if(n == 1) cout << "9 8"; else if(n == 2) cout << "6 4"; else if(n&1)cout << n*3 << " " << 2*n; else cout << 2*n << " " << n; return; } void taskA(){ ll n; cin >> n; cout << 9*n << " " << 8*n << "\n"; return; }
void taskB(){ int n,m; cin >> n >> m; vector<int> a(n,0), b(n,0), c(n,0); _for(i,0,n) cin >> a[i]; _for(i,0,n) cin >> b[i]; sort(b.begin(), b.end()); sort(a.begin(), a.end()); int m1 = b[0]; set<int> s; _for(i,0,n) { int x = (m1-a[i]+m)%m; _for(j,0,n) c[j] = (a[j]+x)%m; sort(c.begin(), c.end()); int f = 0; _for(j,0,n) if(c[j] != b[j]) {f = 1; break;} if(!f) {s.insert(x);} } //sort(ans.begin(), ans.end()); //int y = ans[0]; //cout << y << "\n"; cout << *s.begin() << "\n"; return; }
void taskC(){ int n,k; cin >> n >> k; string s,t; cin >> s; int f = 0; t = s; _for(i,k,n) t[i] = t[i-k]; if(t >= s) { cout << n << "\n" << t <<"\n"; return; } for(int i = k-1; i >= 0; i--) { if(t[i] != '9') { for(int j = i; j < n; j += k) t[j]++; break; }else { for(int j = i; j < n; j += k) t[j] = '0'; } } cout << n << "\n" << t << "\n"; return; }
void taskD(){ int n; cin >> n; //vector<int> a(n); ll a1 = 0, b1 = 0; _for(i,0,n) { ll x; cin >> x; ll a = (x+1)/2; ll b = (x-a); if(i&1) a1 += a, b1 += b; else a1 += b, b1 += a; } cout << min(a1, b1) << "\n"; return; }
int main(){ ios::sync_with_stdio(false), cin.tie(nullptr); //taskA(); //taskB(); //taskC(); taskD(); return 0; }