Codeforces Round #690 (Div. 3)
1462A. Favorite Sequence
简单看懂题即可,左边输出一个然后右边输出一个。
void solve() {int n;cin >> n;vector<ll> a(n + 1);// ll a[n + 1]; //两种写法均可for (int i = 1; i <= n; ++i)cin >> a[i];int l = 1, r = n;bool f = true;for (int i = 1; i <= n; ++i) {if (f)cout << a[l++] << " ", f = false;elsecout << a[r--] << " ", f = true;}cout << endl;}
1462B. Last Year’s Substring
一开始想错了,正确的思路是拆分字符串看是否能组成 2020
void solve() {int n;string s;cin >> n >> s;bool f = false;for (int fir = 0; fir <= 4 && !f; fir++) {int sec = 4 - fir; //定位if (s.substr(0, fir) + s.substr(n - sec) == "2020")f = true;}cout << (f ? "YES\n" : "NO\n");}
1462C. Unique Number
😂打表。注意一下n > 45的话直接输出-1(因为0~9都被使用了最多到45)
ll a[51] = {0, 1, 2, 3, 4, 5, 6, 7,8, 9, 19, 29, 39, 49, 59, 69,79, 89, 189, 289, 389, 489, 589, 689,789, 1789, 2789, 3789, 4789, 5789, 6789, 16789,26789, 36789, 46789, 56789, 156789, 256789, 356789, 456789,1456789, 2456789, 3456789, 13456789, 23456789, 123456789, -1, -1,-1, -1, -1,};void solve() {int n, cnt = 0;string s;cin >> n;cout << a[n] << endl;}
当然也可以正常分析:
void solve() {int n;cin >> n;if (n > 45) {cout << -1 << endl;return;}string s;int nxt = 9;while (n > 0) {if (n >= nxt) {s += '0' + nxt;n -= nxt--;} else {s += '0' + n;break;}}reverse(s.begin(), s.end());cout << s << endl;}
D. Add to Neighbour and Remove
void solve() {int n;cin >> n;vector<ll> a(n);for (int i = 0; i < n; ++i)cin >> a[i];ll ans = INT_MAX, sum = 0;for (int i = 0; i < n; ++i) {sum += a[i];ll cur = 0, toadd = 0;bool f = true;for (int j = 0; j < n; ++j) {if (cur)toadd++;cur += a[j];if (cur > sum) {f = false;break;} else if (cur == sum)cur = 0;}if (f && cur == 0) {// cout << toadd << " " << i << endl;ans = min(ans, toadd);}}cout << ans << endl;}
E1. Close Tuples (easy version)
//unsolved
