NOIP simulation 1003

Sky Dragon

Osiris has a red, b yellow, c blue, he wanted to use to draw the best picture, but need at least a red x, y and z blue yellow, it seems that is not enough. Do not worry, Osiris will be magic! He can put any two of the same color into a another color! Will he ever finish it?

t<=100,0<=a,b,c,x,y,z<=1000000。

answer

I would like to know a little bit does not exist to take their useful to help others, and let others help themselves, so to see more directly how much space can be filled out on the line.

 

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

int t,a,b,c,x,y,z;

int main(){
    freopen("osiris.in","r",stdin);
    freopen("osiris.out","w",stdout);
    scanf("%d",&t);
    while(t--){
        int tot=0,need=0;
        scanf("%d%d%d%d%d%d",&a,&b,&c,&x,&y,&z);
        if(a>x) tot+=(a-x)>>1;
        else need+=x-a;
        if(b>y) tot+=(b-y)>>1;
        else need+=y-b;
        if(c>z) tot+=(c-z)>>1;
        else need+=z-c;
        printf("%s\n",tot>=need ? "YES" : "NO");
    }
}
/*
3
4 4 0 2 1 2
5 6 1 2 7 2
3 3 3 2 2 2
*/
osiris

 


Kyoshin soldiers

Oberthur Leask giant magic is very fond of a directed graph, one day he found a directed graph n vertices and m edges.

Oberoi Leask did not believe a directed graph ring is beautiful, I ask how many sub-graphs (ie a selected set of edges) have this picture is beautiful? The answer to the modulo 1,000,000,007.

40% of the data for n <= 5, m <= 20;

60% of the data for n <= 10;

80% of the data for n <= 15;

To 100% of the data n <= 17.

answer

Now only 40% of the practice, and on the last sentence with a ring topology enumeration edge of violence.

#include<ctime>
#include<queue>
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=1000000007;
const int maxn=20;
const int maxm=250;
int n,m,ret;
int cnt,du[maxn],d[maxn];
vector<int> c[maxn];
struct edge{
    int x,y;
}e[maxm];

template<class T>inline void read(T &x){
    x=0;int f=0;char ch=getchar();
    while(!isdigit(ch)) {f|=(ch=='-');ch=getchar();}
    while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x = f ? -x : x ;
}

int topsort(){
    queue<int> q;
    int tot=0;
    for(int i=1;i<=n;i++){
        d[i]=du[i];
        if(!du[i]) q.push(i),tot++;
    }
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(unsigned int i=0;i<c[x].size();i++){
            int y=c[x][i];
            if(d[y]){
                d[y]--;
                if(!d[y]) q.push(y),tot++;
            }
        }
    }
    return tot==n;
}

void dfs(int s){
    if(!topsort()) return ;
    if(s>m){
        ret++;
        if(ret>=mod) ret-=mod;
        return ;
  }
    dfs(s+1);
    du[e[s].y]++;
    c[e[s].x].push_back(e[s].y);
    dfs(s+1);
    c[e[s].x].pop_back();
    du[e[s].y]--;
}

int main(){
    freopen("obelisk.in","r",stdin);
    freopen("obelisk.out","w",stdout);
    read(n);read(m);
    for(int i=1;i<=m;i++) read(e[i].x),read(e[i].y);
    dfs(1);
    printf("%d",ret);
}
obelisk

Titan

Titan pull liked the least common multiple, one day he thought of a title on the least common multiple.

Seeking to satisfy the following condition number (a, b) of the number of: a, b are positive integers, and a, b <= n and lcm (a, b)> n. Which of course represents the least common multiple lcm. The answer to the modulo 1,000,000,007

To 100% of the data n <= 10000000000.

answer

Number theory is not only shining others say

Du screen what to teach, but I'll say I get understanding

Complement converter (stand)

Then consider lcm (i, j) <= n of

$\sum_{i=1}^{n}\sum_{j=1}^{n}[gcd(i,j)\leq n]$

$\sum_{k}\sum_{i=1}^{n}\sum_{j=1}^{n}[gcd(\frac{i}{k},\frac{j}{k})=1][\frac{ij}{k}\leq n]$

$\sum_{k}\sum_{i=1}^{n}\sum_{j=1}^{n}\sum_{d|gcd(\frac{i}{k},\frac{j}{k})}\mu (d)[\frac{ij}{k}\leq n]$

$\sum_{k}\mu (d)\sum_{d|\frac{i}{k}}^{n}\sum_{d|\frac{j}{k}}^{n}[\frac{ij}{k}\leq n]$

$\sum_{k}\mu (d)[\frac{ij}{k}\leq \frac{n}{d^2}]$

$\mu (d)\sum_{k}[\frac{i}{k}\frac{j}{k}k\leq \frac{n}{d^2}]$

$\frac{n}{d^2}\geq 1,\therefore d\leq \sqrt n$

Therefore, considering enumeration d, to find the matching $ \ frac {i} {k }, \ frac {j} {k}, k $

$ Assumed \ frac {i} {k} \ leq \ frac {j} {k} \ leq k $

$\frac{i}{k}\leq \sqrt[3]{\frac{n}{d^2}},\frac{j}{k}*\frac{j}{k}\leq\frac{n}{d^2i}$

So we can get two before enumeration range of k, you know how many meet the conditions, and then consider the three interchangeable (because they would no size relationship), to discuss the classification.

Finally, the answer is n * n- find answers

 

#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int mod=1000000007;
const int maxn=100000;
ll n,m,ans;
int prime[maxn+5],mu[maxn+5];
bool not_prime[maxn+5];

void init(){
    mu[1]=1;
    for(int i=2;i<=maxn;i++){
        if(!not_prime[i]){
            prime[++prime[0]]=i;
            mu[i]=-1;
        }
        for(int j=1;j<=prime[0]&&i*prime[j]<=maxn;j++){
            not_prime[i*prime[j]]=true;
            if(i%prime[j]) mu[i*prime[j]]=-mu[i];
            else {
                mu[i*prime[j]]=0;
                break;
            }
        }
    }
}

int main(){
    freopen("ra.in","r",stdin);
    freopen("ra.out","w",stdout);
    scanf("%lld",&n);
    init();
    m=sqrt(n+0.5);
    for(int d=1;d<=m;d++){
        ll val=n/d/d,ret=0;
        for(ll i=1; I * I * I <= Val; I ++)
          For (LL J = I; J * J <= Val / I; J ++ ) { 
              LL C = Val / I / J-J + . 1 ;
               // I * J * K <= Val, I <= J <= K
               // C: number of values of k 
              IF (J == I) RET = (RET + . 1 + (the C- . 1 ) * . 3 ) MOD%; // . 1: J == k, otherwise i, j, k three permutations of 
             the else RET = (RET + . 3 + (the C- . 1 ) * . 6 )% MOD; 
         } 
        ANS = (ANS + MU [D] * RET)% MOD; 
    } 
    ANS = (n-% MOD) * (n-% MOD) mod-% ANS; 
    ANS = (ANS% + MOD MOD)%mod;
    printf("%lld",ans);
}
out

 

Guess you like

Origin www.cnblogs.com/sto324/p/11620673.html