• 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;
    } 
    
  • 相关阅读:
    mysql5.7 tar包安装
    jpa2.0以上findOne和getOne的区别
    终端设置代理
    virtualbox EFI安装Archlinux
    无法在web.xml或使用此应用程序部署的jar文件中解析绝对uri:[http://java.sun.com/jsp/jstl/core]
    代理模式笔记
    Mybatis详细的执行流程
    javaweb超市管理系统demo
    CF1409F Subsequences of Length Two
    1002: [FJOI2007]轮状病毒 基尔霍夫矩阵
  • 原文地址:https://www.cnblogs.com/lightac/p/13769455.html
Copyright © 2020-2023  润新知