Codeforces Round #675 (Div. 2)
题目链接:http://codeforces.com/contest/1422
A题
签到题
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MODE = 1e9 + 7; string s; int main () { cin >> s; ll n = s.size(); ll temp = 0; for(int i = 0; i < n; ++i) { temp += s[i] - '0'; } ll po = 1; ll sum = 0; for(ll i = n - 1; i >= 0; --i) { ll x =s[i] - '0'; temp -= x; sum += temp * (n - i) % MODE * po % MODE; //之后 sum += x * i * (i + 1) / 2 % MODE * po % MODE; //算上这位 sum %= MODE; po *= 10; po %= MODE; } cout << sum << endl; }
B题
思维题
对称四元组全部变成四个中第二大的数
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll get(ll a, ll b,ll c, ll d) { vector<ll> v(4); v[0] = a; v[1] = b; v[2] = c; v[3] = d; sort(v.begin(), v.end()); return v[1]; } int main () { int t; cin >> t; while(t--) { ll v[110][110]; int n, m; cin >> n >> m; ll sum = 0; for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { cin >> v[i][j]; } } for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { sum += abs(v[i][j] - get(v[i][j], v[n - 1 - i][j], v[i][m - 1 - j], v[n - 1 -i][m - 1 - j])); } } cout << sum << endl; } }
C题
数论题
有点儿灵性得看出每一位对于答案的贡献
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MODE = 1e9 + 7; string s; int main () { cin >> s; ll n = s.size(); ll temp = 0; for(int i = 0; i < n; ++i) { temp += s[i] - '0'; } ll po = 1; ll sum = 0; for(ll i = n - 1; i >= 0; --i) { ll x =s[i] - '0'; temp -= x; sum += temp * (n - i) % MODE * po % MODE; //temp代表的是x之前所有数的和,乘以po之后代表,对于其的贡献 sum += x * i * (i + 1) / 2 % MODE * po % MODE; //i(i+1)/2是求和。代表的是x选择后左边不同位数可以选择的情况总数 sum %= MODE; po *= 10; po %= MODE; } cout << sum << endl; }
作者:LightAc
出处:https://www.cnblogs.com/lightac/
联系:
Email: dzz@stu.ouc.edu.cn
QQ: 1171613053
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。