[12.18] Diary

12.18

CF GlobalRound 6

Unfortunately Efst, or else can be directly estimated on purple.

A.Competitive Programmer

Meaning of the questions: give a number, it asks whether there is a permutation that is a multiple of 60?

Thinking : 60 fold - containing 0 and multiples of 6 - 0, and containing a number of bits and a multiple of 2 and 3 - and having a number of bits 0 and 3 and because of having a 02,468

#include<bits/stdc++.h>
using namespace std;
const int M=1e5+20;
char s[M];
int main(){
    int n;
    scanf("%d",&n);
    for(int z=1;z<=n;++z){
        scanf("%s",s);
        int len=strlen(s),sum=0;
        int vou=0,v0=0;
        for(int i=0;i<len;++i){
            if (s[i]=='0')
                ++v0;
            else if ((s[i]-'0')%2==0)
                ++vou;
            sum+=s[i]-'0';
        }
        if (((v0>=2)||(v0&&vou))&&sum%3==0)
            printf("red\n");
        else
            printf("cyan\n");
    }
    return 0;
}

B.Dice Tower

Meaning of the questions: a bunch of dice can heap on the ground, exposed to the sides and the top part is that one. Now, given a number, and asked whether there is a method of pile of dice, making the exposed portion is equal to this number?

Solution: In addition to the top, each averaging 14 dice. The top number is likely to 123456. Thus n% 14 = 1-6 can be. But to special sentenced to 1-6 it is not acceptable.

#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main(){
    int n;
    scanf("%d",&n);
    for(int z=1;z<=n;++z){
        LL c;
        scanf("%I64d",&c);
        if ((c/14)&&(1<=c%14&&c%14<=6))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

C.Diverse Matrix

Question is intended: to a matrix r * c, b corresponding to the array of each row is the number of + gcd each column. It is a diverse matrix, i.e., not the same number of each of the array b. B = the maximum value of magnitude in a matrix array, given r and C Q, construct a matrix of minimum magnitude, and outputs.

Thinking: minimum situation is exactly the array b 1-r + c these numbers, the magnitude of r + c, which is the smallest case. The following ponder how to construct this matrix. It has an easy understanding of the nature, i.e. for any k> = 1, there gcd (k, k + 1) = 1. Thus we set A [i] [j] = R [i] C [i], where R = {1,2,3, ......, r }, C = {r + 1, r + 2, ......, r + c} can satisfy the condition. B values because the value of the array are in each column corresponding to a pile of consecutive numbers by which gcd b must be equal to the corresponding array, the meaning of the title is satisfied.

Note that r = 1, or c = 1, this time must be the width of the key a number value of 1, or be wrong.

I.e. 4 * 1 matrix 2345 must not be 5,101,520.

#include<bits/stdc++.h>
using namespace std;
const int M=600;
int a[M][M],R[M],C[M];
int main(){
    int r,c;
    scanf("%d%d",&r,&c);
    if (r==1&&c==1){
        printf("0\n");
        return 0;
    }
    int cnt=0;
    if (r<c){
        for(int i=1;i<=r;++i)
            R[i]=++cnt;
        for(int i=1;i<=c;++i)
            C[i]=++cnt;
    }
    else{
        for(int i=1;i<=c;++i)
            C[i]=++cnt;
        for(int i=1;i<=r;++i)
            R[i]=++cnt;
    }
    for(int i=1;i<=r;++i)
        for(int j=1;j<=c;++j)
            a[i][j]=R[i]*C[j];
    for(int i=1;i<=r;++i){
        for(int j=1;j<=c-1;++j)
            printf("%d ",a[i][j]);
        printf("%d\n",a[i][c]);
    }
    return 0;
}

D.Decreasing Debts

The meaning of problems: there are n individuals in debt to each other, and asked whether optimized so that the sum of the smallest debt, no debt involved to ensure that those least likely. Debt relationship after the output optimization.

Ideas: This title is very BroadenGate ...... directly calculated each person's net income, in which case the debt is the sum of the minimum (absolute value and / 2), even after the casual side of the line, a relationship that is depleted every time guarantee can.

#include<bits/stdc++.h>
using namespace std;
const int M=1e5+20;
struct E{
    int u,v,w;
    E(int a=0,int b=0,int c=0):u(a),v(b),w(c){}
};
queue<int> upd;
queue<int> pnt[M][2];
vector<E> edge;
int vis[M];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i){
        int u,v,d;
        scanf("%d%d%d",&u,&v,&d),edge.push_back(E(u,v,d));
        pnt[u][0].push_back(edge.size()-1),pnt[v][1].push_back(edge.size()-1);
    }
    for(int i=1;i<=n;++i)
        vis[i]=1,upd.push(i);
    while(!upd.empty())
        if (!pnt[i][0].empty()&&!pnt[i][1].empty()){
            while(!pnt[i][0].empty()&&edge[pnt[i][0].front().w==0])
                pnt[i][0].pop();
        }
    return 0;
}

E. Spaceship Solitaire

Meaning of the title: the n-kind resources, each resource are at least \ (a_i \) to win time. Only produce one unit of a resource every day. But there are some awards, each award is t, s, u, that is, have a \ (t_j \) but in the \ (s_j \) resource, you can get a unit \ (u_j \) resources. Now a reward every time you modify or delete / add a bonus, each output at least a few rounds of victory.

Problem solution: fst up. My thinking is that every bonus necessarily apply, so only need to record it in addition to all the bonus, how many resources also need to add. Fix the back.

Guess you like

Origin www.cnblogs.com/diorvh/p/12078792.html