- #include <iostream>
- using namespace std;
- int main()
- {
- string s;
- cin>> s;
- int cnt1 = 0, cnt2 = 0;
- for(int i = 0; i <4; i++)
- {
- if('+' == s[i])
- {
- cnt1++;
- }
- else
- {
- cnt2++;
- }
- }
- cout << cnt1 - cnt2;
- return 0;
- }
B 题
- #include <iostream>
- using namespace std;
- int main()
- {
- int num;
- cin>> num;
- int temp = num;
- int n = 0;
- while(temp)
- {
- n += temp % 10;
- temp /= 10;
- }
- if(0 == num % n)
- {
- cout <<"Yes";
- }
- else
- {
- cout << "No";
- }
- }
C 题
分析: 因为最小的数为 1, 最终所有的数必然全变为 1. 计算 1 左边和右边的数各分为多少段, 加起来即可得到结果.
假设 1 位于第 i 个位置, 则左边的分段为 (i - 1) / (k - 1), 右边的分段为 (n - i) / (k - 1),
加起来 (i - 1) / (k - 1) + (n - i) / (k - 1) = (n - 1) / (k - 1)
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, k;
- cin>> n>> k;
- int a[n + 1];
- for(int i = 1; i <= n; i++)
- {
- cin>> a[i];
- }
- int ans = (n - 1) / (k - 1);
- if(0 != (n - 1) % (k - 1))
- {
- ans += 1;
- }
- cout <<ans;
- return 0;
- }
D 题
官方题解:
- https://img.atcoder.jp/arc099/editorial.pdf
- #include<iostream>
- using namespace std;
- typedef long long LL;
- double s(LL n)
- {
- LL x = n;
- LL y = 0;
- while (x)
- {
- y += x % 10;
- x /= 10;
- }
- return (double)n / y;
- }
- int main()
- {
- LL K;
- LL n = 1;
- LL x = 1;
- cin>> K;
- for (int i = 0; i <K; i++)
- {
- cout << n << endl;
- if (s(n + x)> s(n + x * 10))
- {
- x *= 10;
- }
- n += x;
- }
- return 0;
- }
TopCoder & Codeforces & AtCoder 交流 QQ 群: 648202993
来源: http://www.jianshu.com/p/6d7bd9a588f7