codeforces/contest/1228

B. Filling the Grid

Branches and columns were stained Saowan map grid number is not dyed after the contribution is to answer produced, wa the first serve, because the sample did not see, there will be conflict situations produce the answer in this case is 0

#include<bits/stdc++.h>
const double pi=3.14159;
typedef long long int ll;
const int mod=1e9+7;
int amap[1010][1010];
int hh[1010],ww[1010];
 
ll qpow(ll a,ll b){
ll res=1;
while(b>0){
    if(b&1){
 
        res=res*a%mod;
    }
    b=b>>1;
    a=a*a%mod;
 
}
return res;
}
 
 
int main(){
 
int h,w;
scanf("%d%d",&h,&w);
for(int i=1;i<=h;i++){
    scanf("%d",&hh[i]);
}
for(int i=1;i<=w;i++){
    scanf("%d",&ww[i]);
}
for(int i=1;i<=h;i++){
    for(int j=1;j<=hh[i];j++){
        amap[i][j]=1;
    }
    amap[i][hh[i]+1]=-1;
}
 
for(int i=1;i<=w;i++){
    for(int j=1;j<=ww[i];j++){
            if(amap[j][i]==-1){
                printf("0\n");
                return 0;
            }
            else
                amap[j][i]=1;
    }
    if(amap[ww[i]+1][i]==1){
          printf("0\n");
        return 0;
    }
    else
        amap[ww[i]+1][i]=-1;
}
 
int cnt=0;
for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
    //printf("%d ",amap[i][j]);
        if(amap[i][j]==0)
            cnt++;
    }
    //printf("\n");
}
//printf("cnt:%d\n",cnt);
 
 
    printf("%lld",qpow(2,cnt));
 
return 0;
}

C. Primes and Multiplication

It defines three operations 

 g(x,p)、 f(x,y)、prime(x)

1, prime (x) is defined as the set of prime factors of x.

Let prime(x)prime(x) be the set of prime divisors of xx. For example, prime(140)={2,5,7}prime(140)={2,5,7}, prime(169)={13}prime(169)={13}.

2, g (x, p) is defined as a factor of x, the factor is k times p, and k be the largest.

Let g(x,p) be the maximum possible integer pkpk where kk is an integer such that xx is divisible by pkpk. For example:

  • g(45,3)=9 (45 is divisible by 3^2=9 but not divisible by 3^3=27),
  • g(63,7)=7 (63 is divisible by 7^1=7 but not divisible by 7^2=49).

3, f (x, y) is defined as the product of g (y, p), p is an element prime (x) set.

Let f(x,y) be the product of g(y,p)g(y,p) for all in prime(x)prime(x). For example:

  • f(30,70)=g(70,2)g(70,3)g(70,5)=2^13^05^1=10
  • f(525,63)=g(63,3)g(63,5)g(63,7)=3^25^07^1=6

 Finally, an x, n, obtains f (x, 1) * f (x, 2) ...... * f (x, n) of the product

Data range: The only line contains integers x and n (2x10^9 1n10^18) — the numbers used in formula.

Very complex topic, read skull pain.

Slowly analysis

1, for a given x, we can start with a prime factor decomposition, because sooner or later to use

2, final demand is the product of more than f (x, y), so even by 1 can be ignored, then how will it produce 1?

Obviously, g (y, p), it is not a factor y p itself, it will be 1

3, this time we will naturally think, for 1 ~ n this section, the order of a factor of the product of Pi is the answer

For example, x = 6, n = 11

prime (x) = {2,3};

Then it is determined g (1,2) * g (2,2) * g (3,2) ...... * g (11,2) * g (1,3) * f (2,3) ...... * g (11,3)

This time we can find,

6, 10 contribution is 2,2 ^ 1;

4 contribution is 4,2 ^ 2;

8 contribution is 8,2 ^ 3;

The contribution is 3,6 3,3 ^ 1;

9 contribution is 9,3 ^ 2;

At this time becomes a subject, obtaining 1 ~ n, the product of the maximum prime factor of the number of power and the number of all primes factors.

When problems surface look, we will find prime numbers in the range of 1 ^ 9, not a sieve Euler range (may have to improve what can screen out the way, but I was too dishes, and can not think)

But think again, 1e5 * 1e5 = 1e10> 1e9 screen so long as all the prime numbers within a range of 1e5, last look at this in itself is not a prime number on it.

Another problem is the power factor of the maximum number of prime numbers, this factor of 2, 4 for the time, the contribution is 4 for 8 this number, the contribution is 8, I do not know how to calculate, finally saw online someone else's blog

Although understand a treatment method, but do not know what principle do not know, anyway, so after using it.

Anyway, nothing wrong.

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string.h>
#include<set>
using namespace std;
const double pi = 3.14159;
typedef long long int ll;
const int mod = 1e9 + 7;
long long int maxn = 1e5, m, n;
bool number[100005];
ll prime1[100005];
ll prime[100005];
int c = 0;
int c1 = 0;
void isprime()
{
 
    int i, j;
    memset(number, true, sizeof(number));
    for (i = 2; i <= maxn; i++)
    {
        if (number[i]) {
            prime[c++] = i;
 
        }
        for (j = 0; j<c&&prime[j] * i <= maxn; j++)
        {
            number[prime[j] * i] = false;
 
            IF (I% Prime [J] == 0 ) // ensure that each composite number will only be the smallest prime factor of its screen to so that each number is marked only once 
                BREAK ; 
        } 
    } 
} 
 
LL qpow (LL A, B LL) { 
    LL RES = . 1 ;
     the while (B> 0 ) {
         IF (& B . 1 ) 
            RES = RES * A% MOD; 
        B = B >> . 1 ; 
        A = A * A% MOD; 
    } 
    return RES; 
} 
 
int main () { 
    isPrime (); 
    Scanf ( " % LLD LLD%", &m, &n);
    for (int i = 0; i<c; i++) {
        if (m<prime[i])
            break;
        if(m%prime[i] == 0){
            prime1[c1++] = prime[i];
        }
        while(m%prime[i]==0)
            m/=prime[i];
    }
    if(m>1)
        prime1[c1++]=m;
    ll x;
    ll ans = 1;
    ll cnt = 0;
 
    for (int i = 0; i<c1; i++) {
        x = n;
        cnt = 0;
        while (x) {
            cnt += x / prime1[i];
            x /= prime1[i];
        }
        ans = ans*qpow(prime1[i], cnt) % mod;
    }
    printf("%lld\n", ans);
 
    return 0;
}

D. Complete Tripartite

To a map

And a little edge, no edge weight, no loopback,

Is divided into three, each set, the elements are not connected to each other, and the other two elements are connected one by one in FIG.

This is not to sweep staining get away again?

Or out of the wa, there may be a side not, there may be insufficient number of sides, some point to useless

Add a vis maintenance and cnt

Violence miracle!

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string.h>
#include<set>
using namespace std;
const double pi = 3.14159;
typedef long long int ll;
const int mod = 1e9 + 7;
long long int maxn = 1e5 + 9;
int n, m;
int color[300005];
int vis[300005];
int cnt1, cnt2, cnt3;
struct node {
    int s, t;
}p[300005];
bool cmp(node a, node b) {
    if (a.s == b.s)
        return a.t < b.t;
    else
        return a.s < b.s;
}
int main() {
    scanf("%d %d", &n, &m);
    int a, b;
    for (int i = 1; i <= n; i++)color[i] = 1;
    for (int i = 1; i <= m; i++) {
        scanf("%d %d", &a, &b);
        vis[a]++;
        vis[b]++;
 
        p[i].s = min(a, b);
        p[i].t = max(a, b);
 
    }
    sort(p + 1, p + 1 + m, cmp);
    for (int i = 1; i <= m; i++) {
        a = p[i].s, b = p[i].t;
        if (color[a] != color[b])
            continue;
        else {
            if (color[a] == 3)
            {
                printf("-1\n");
                return 0;
            }
            else {
                color[b] = color[a] + 1;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (color[i] == 1)
            cnt1++;
        else if (color[i] == 2)
            cnt2++;
        else
            cnt3++;
    }
    if (cnt1 == 0 || cnt2 == 0 || cnt3 == 0) {
        printf("-1\n");
        return 0;
    }
    for (int i = 1; i <= n; i++) {
        if (color[i] == 1 && vis[i] == cnt2 + cnt3&&vis[i]) {}
        else if (color[i] == 2 && vis[i] == cnt1 + cnt3&&vis[i]) {}
        else if (color[i] == 3 && vis[i] == cnt1 + cnt2&&vis[i]) {}
        else {
            printf("-1\n");
            return 0;
        }
    }
    for (int i = 1; i <= n; i++)
        printf("%d ", color[i]);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/wjune-0405/p/11617283.html