ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforces Global Round 6

2019-12-18 23:00:08  阅读:232  来源: 互联网

标签:MB int cin Global Codeforces standard input di Round


  • A. Competitive Programmer   standard input/output1 s, 256 MB  x5632

    模拟一下,需要能整除60  字符串中需要 能整除2 3 10,所以需要字符串各位数之和能整除3 并且有 一个偶数和一个0  或者两个0也行, 特殊情况 全为0 也行,

  • B. Dice Tower  standard input/output 1 s, 256 MB 

    一开始想错了,打算是 n 可以由多少个21-k个数构成, WA了两发, 纸上多画了几个发现应该是 由 x 个 骰子构成  n = x*14+y  (y>=1 && y<=6)  因为骰子叠起来一定会有上下两个面被挡住 而骰子是标准的 1-6  2-5  3-4 所以两个上下的骰子的点数之和为7   相当于 每个骰子的贡献只有四个侧面, n 等于 x个骰子的侧面 加 一个最上面的面  so   cout <<  (n%14<=6&&n%14>=1 ? "YES\n":"NO\n")

  • C. Diverse Matrix  standard input/output1 s, 256 MB 

    开始没有头绪 没有看懂题面, 直接手推了几组数据 找到了规律  相当于 输入r c, 你需要输出 r 行 c列的矩阵  而矩阵的每行每列的最大公约数 构成一个新的数组, 数组的每个元素 需要是唯一的 且 需要minimizing the magnitude 就是说数组的最大值最小, 那么最小的情况就是 1 2 3 4 5 ………… c+r,我们可以这样构造矩阵 第一行为
第一行为  2      3     ……   c+r

第二行为  2*2   3*2  ……  2*(c+r)

第三行为  2*3   3*3  ……  3*(c+r)   

.

.

.

这样就可以构造一个 1 2 3 4 ………… c+r 的数组了, 然而zz的我写的时候没注意 1*r 和 r*1 的情况, Wrong answer on pretest 4, zz

  • D. Decreasing Debts  standard input/output2 s, 256 MB 

  想了半天, 但是题目给的第一个性质不会用, 且不知道用容器什么储存, 大概想的是用一个map数组存储  ((pair)ui,vi  di) , 再将ui,vi相同的合并下 di  合并完以后跑一遍找最小的 di值, 再跑一遍 所有的di 都减去最小的di值, 最后输出剩下 di不为 0 的个数, 和 具体 ui,vi di, enmmmmmmm 然后不会写。。。。。 而且思路也有问题 题目意思应该不是这样。。。

  题解是不记录具体的借债关系, 只记录借债人欠债金额 和 债主借出的具体金额 (欠钱为-  借钱为+),  每个人的金额为正或者负()

类似于 1借给2 100元  2借给3 70元  3借给4 50元  可以直接转化为  1借给2 30元  1借给3 20元  1借给4 50元, 将中间的关系简化  ,每个人只能是欠钱 或者 借钱, 
每次找到一个债主A  然后 减去每个借钱人 最多从债主A借的钱x  记录下他们的关系, 债主A的钱-x  直到A没钱, 到下一个债主 
每个债主的钱直接借给某人  输出这样的关系 和 金额 即可,

  Let d(a,b)>0d(a,b)>0 and d(c,d)>0d(c,d)>0 such that a≠ca≠c or b≠db≠d.

  We can decrease the d(a,b)d(a,b) and d(c,d)d(c,d) by zz and increase d(c,b)d(c,b) and d(a,d)d(a,d) by zz,

  where 0<z≤min(d(a,b),d(c,d))0<z≤min(d(a,b),d(c,d)).

  • E. Spaceship Solitaire  standard input/output1 s, 256 MB 
  • F. Almost Same Distance  standard input/output5 s, 256 MB 
  • G. Permutation Concatenation   standard input/output1 s, 256 MB 
  • H. Red-Blue Graph   standard input/output4 s, 512 MB 
#include <bits/stdc++.h>

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 taskA(){
    int t; 
    cin >> t;
    while(t--){
        string s; cin >> s;
        int a = 0, b = 0,d = 0;
        sort(s.begin(), s.end());
        if(s[0] == s[s.size()-1] && s[0] == '0')
        {
            cout << "red\n"; continue;  
        }
        for(auto c:s) {
            int x = c-'0';
            if(x == 0) b++;
            if(x && x%2 == 0) d = 1;
            a += x;
        }
        if(a%3==0 && (b>=2 || (b&&d))){
            cout << "red\n";    continue;  
        }
        cout << "cyan\n";
    }
    return;
}

 

void taskB(){
    int t;
    cin >> t;
    while(t--){
        ll n;
        cin >> n;
        ll y = (n)%14;
        if(n < 15) cout << "NO\n";
        else if(y >= 1 && y <= 6) cout << "YES\n";
        else cout << "NO\n";
    }
    return;
}

 

void taskC(){
    int c,r; cin >> r >> c;
    int x = r+c; 
    if(r == 1 && c == 1) { cout << "0\n"; return;}
    ll b[505][505];
    if(r == 1) {_rep(i,1,c) cout << i+1 << (i==c?"\n":" ");return; }
    if(c == 1) {_rep(i,1,r) cout << 1+i << "\n";return;}
    _rep(i,1,r)
      _rep(j,1,c)
        {
            if(i==1)b[i][j] = x*i;
            else b[i][j] = b[1][j]*i;
            x--;
        }

    _rep(i,1,r) _rep(j,1,c) cout << b[i][j] << (j==c ?"\n" : " ");
    
    return;
}

 

void taskD(){
    int n,m; cin >> n >> m;
    //map<pair<int, int>, int> cnt;
    vector<ll> a(n+1, 0);
    vector<pair<pair<int, int>, ll> >mp;

    _rep(i,1,m) {
        int x, y, z; cin >> x >> y >> z;
        a[x] += z, a[y] -= z;
    }

    int x = 1, y = 1;
    for(; x <= n; x++) {
        if(a[x] <= 0) continue;
        while(a[x]) {
            for(; y <= n && a[y] >= 0; y++);
            ll mi = min(-a[y], a[x]);
            mp.push_back(make_pair(make_pair(x, y), mi));
            a[y] += mi, a[x] -= mi;
        }
    }
    n = mp.size();
    cout << n << '\n';
    for(auto it:mp) cout << it.first.first << " " << it.first.second 
                         << " " << it.second << "\n";
    return;
}

 

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    //taskA();
    //taskB();
    //taskC();
    taskD();
    return 0;
}

 

标签:MB,int,cin,Global,Codeforces,standard,input,di,Round
来源: https://www.cnblogs.com/163467wyj/p/12064472.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有