2019 cattle off the National Day party training day1

2019 cattle off the National Day party training day1

// 2019.10.1 Day practice match
// link game: 2019 cattle off the National Day party training DAY1
// Day seven days although I slipped go home, I urge teammates still a good play ...

// After all, the scene did not match a few days, a good practice Ha

 

A whole sub-matrix

Subject to the effect

Determining whether there is a sub-matrix matrix satisfies \ (x_1 \ le x \ le x_2, y_1 \ le y \ \ le y_2) the whole is 1, 0 elsewhere.

Water problem, determine what can be violent.

 

AC Code

#include<iostream>
#include<cstdio>
using namespace std;

char mat[15][15];
int n, m;
int x1, y1, x2, y2;

void check() {
    for(int i=x1;i<=x2;i++) {
        for(int j=y1;j<=y2;j++) {
            if(mat[i][j]=='1') {
                mat[i][j] = '0';
            }else {
                printf("No\n");
                return;
            }
        }
    }
    
    for(int i=0;i<n;i++) {
        for(int j=0;j<m;j++) {
            if(mat[i][j]=='1') {
                printf("No\n");
                return;
            }
        }
    }
    printf("Yes\n");
    
}

int main() {
    while(scanf("%d %d", &n, &m)!=EOF) {
        for(int i=0;i<n;i++)
            scanf("%s", mat[i]);
        
        x1 = y1 = x2 = y2 = -1;
        for(int i=0;i<n&&x1==-1;i++) {
            for(int j=0;j<m;j++) {
                if(mat[i][j]=='1') {
                    x1 = i, y1 = j;
                    break;
                }
            }
        }
        
        for(int i=n-1;i>=0&&x2==-1;i--) {
            for(int j=m-1;j>=0;j--) {
                if(mat[i][j]=='1') {
                    x2 = i, y2 = j;
                    break;
                }
            }
        }
        
        if(x1==-1||x2==-1) {
            printf("No\n");
            continue;
        }
        
        check();
    }
    return 0;
}

 

B number of combinations

Subject to the effect

A given n and k, find \ (min (C_n ^ k, 18 is 10 ^ {}) \) .

\ (0 ≤ K ≤ n ≤ 10. 9 ^ \) , up \ (10 ^ 5 \) sets of data.

Thinking

Number of combinations \ (C_ {100} ^ { 50} \) has far exceeded \ (10 ^ {18} \) , then obviously consider using O (n) of recursive find the number of combinations, even \ (10 ^ 5 \) set of data also ran past.

To recap again a combination of the number of recursive

\[C_n^k = \frac {n-k+1} {k} C_n^{k-1}\]

AC Code

Toss a long time before A, noted \ (^ {C_n C_n NK} = ^ K \) , the first k = min (k, nk) , is calculated to ensure that the process is monotonic.

doubleA past, but also to use invincible __int128. After the game can be found long doubleto ensure accuracy.

#include<cstdio>
using namespace std;
typedef long long ll;
//typedef __int128 i128;
const ll INF = 1e18;

ll cal(ll n, ll k) {
    if(k>n/2) k = n - k;
    // i128 res = 1;
    long double res = 1.0;
    for(ll i=1;i<=k;i++) {
        res = res*(n-i+1)/i;
        if(res>INF) return INF; 
    }
    return (ll)res;
}

int main() {
    ll n, k;
    while(scanf("%lld %lld", &n, &k)!=EOF) {
        printf("%lld\n", cal(n, k));
    }
    return 0;
}

Elegant simplicity of Python written:

while True:
    try:
        n, k = map(int, input().split())
        k = min(k, n-k)
        
        ans = 1
        for i in range(1, k+1):
            ans = ans * (n-i+1) // i
            if ans>10**18 :
                ans = 10**18
                break   
        print(ans)
    except EOFError:
        break

 

E Numbers

Subject to the effect

There are n the range [0, 99] integer, and now they are connected wrote a number of original array ask how many possibilities.

Thinking

Thought is dp, half-written wrong, rewrite dfs, not the seizure of samples, he slipped. . .

// The original is dfs pos==lenonly ++ ans.

AC Code

#include<cstdio>
#include<iostream>
#include<cstring> 
using namespace std;
 
char s[55];
bool vis[100];
int len;
int ans;
 
void dfs(int pos) {
    if(pos>len) return;
    if(pos==len) {
        ++ans;
        return;
    }
    int n = s[pos]-'0';
    int nn = n*10;
    if(!vis[n]) {
        vis[n] = 1;
        dfs(pos+1);
        vis[n] = 0;
    }
    if(nn && pos<len-1) nn += s[pos+1]-'0';
    if(nn>=10 && !vis[nn]) {
        vis[nn] = 1;
        dfs(pos+2);
        vis[nn] = 0;
    }
}
 
int main() {
    while(scanf("%s", s)!=EOF) {
        memset(vis, 0, sizeof(vis));
        len = strlen(s);
        ans = 0;
        dfs(0);
        printf("%d\n", ans);
    }
    return 0;
}

F 4 Buttons

Subject to the effect

Bobo beginning at the origin (0,0) on a plane, there are four operations: a step up moves to the right, up to the upward movement step b, step c moves to the left most, a maximum downward movement of step d. Q n times the number of different operating points can be reached.

Thinking

Only the operation is very simple step, respectively, you can reach the coordinate axis away from the origin (a, 0), (0, b), (-c, 0), (0, -d). It contains an origin including a total of 1 + a + b + c + d points.

Multi-step, we first look at the situation in the first quadrant:

The first operation reaches the x-axis interval [1, a], the 2nd to n-th in the vertical direction to reach [1, (n-1) b)], a total of a * (n-1) b th point;

Two x-axis operation reaches the interval [a + 1, 2a], the 2nd to n-th in the vertical direction to reach [1, (n-2) b)], a total of a * (n-2) b points;

···

n-1 operations reaches the x-axis interval [(n-2) a + 1, (n-1) a], on the first n 1-th to n-th in the vertical direction to reach [1, b], a total of // two points a * b;

a point operations // n reaches the x-axis furthest [(n-1) a + 1, na].

So the answer is simple, 1 + n (a + b + c + d) + n (n-1) / 2 * (ab + bc + cd + ad).

AC Code

#include<cstdio>
using namespace std;
const int mod = 1e9+7;
typedef long long ll;
ll n, a, b, c, d;
int main() {
    while(scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &c, &d)!=EOF) {
        ll ans = 1 + (a+b+c+d)%mod * n%mod + n*(n-1)/2 %mod
        *((a*b%mod+ b*c%mod + c*d%mod + a*d%mod)%mod)%mod;
        printf("%lld\n", ans%mod);
    }
    return 0;
}

 

Digraph H

Subject to the effect

Math, to be completed, my pot.

Guess you like

Origin www.cnblogs.com/izcat/p/11618652.html