Boy, do you crave power (20,190,831)?

Today, parts of the exam, manual funny

 

 

 

 

A, FFF group

 

Description [title]

In the past, Shylock and Lucar happy life together.

On the eve of Valentine's Day, they go out shopping, met with members of the group activities FFF group, so they will be thrown into the dungeon FFF group and put them into two different rooms in random. Head of the FFF group plans tomorrow they will drown in the sea of ​​flames. But the head of gave them a chance, if they can reach one person to another person in the room (the other person does not move), then let them, otherwise the next day and then the ignition off.

Dungeon there are n rooms, m road, each road connecting the two rooms, and there is a path direction.

Now ask Shylock and Lucar, regardless of whether in any case, they have to meet one of them can reach another room, if the output is "I love you my love and our love save us!", Otherwise output "Light my fire ! "

[Input Format]

This title contains multiple sets of data.

For each test, the first line enter T, for showing the number of data sets.

Following line two integers n, m, denote the number of rooms and the number of paths.

The next m lines of two integers x, y, x represents from room there is a way to reach room y.

After each set of data there is a blank line.

[Output format]

Output line, if you ask Shylock and Lucar, regardless of whether in any case, they have to meet one of them can reach another room, if the output is "I love you my love and our love save us!", Otherwise outputs " Light my fire! "


Even strong wave of deflation points, again a topological sorting

Very nice, very extreme comfort

#include<bits/stdc++.h>
#define re return
#define inc(i,l,r) for(int i=l;i<=r;++i)

using namespace std;
template<typename T>inline void rd(T&x)
{
    char c;bool f=0;
    while((c=getchar())<'0'||c>'9')if(c=='-')f=1;
    x=c^48;
    while((c=getchar())>='0'&&c<='9')x=x*10+(c^48);
    if(f)x=-x;
}

const int maxn=20005,maxm=200005;
int T,n,m,k,hd[maxn],dfn[maxn],low[maxn],belong[maxn];
int tot,col,fr[maxn],to[maxn],fa[maxn],d[maxn];
struct node{
    int fr,to,nt;
}e[maxm];

inline void add(int x,int y)
{
    e[++k].to=y;e[k].nt=hd[x];hd[x]=k;e[k].fr=x;
}

stack<int>s;

inline void tarjan(int x)
{
    s.push(x);
    dfn[x]=low[x]=++tot;
    for(int i=hd[x];i;i=e[i].nt)
    {
        int v=e[i].to;
        if(!dfn[v])
        {
            tarjan(v);
            low[x]=min(low[x],low[v]);
        }
        else if(!belong[v])
            low[x]=min(low[x],dfn[v]);
    }
    
    if(dfn[x]==low[x])
    {
        ++col;
        int v=-1;
        while(v!=x)
        {
            v=s.top();
            s.pop();
            belong[v]=col;
        }
    }
}

inline int find(int x)
{
    re x==fa[x]?x:fa[x]=find(fa[x]);
}

inline bool topo()
{
    int cnt=0;
    k=0;
    inc(i,1,col)hd[i]=0;
        
    inc(i,1,m)
    {
        int x=belong[e[i].fr];
        int y=belong[e[i].to];
        if(x!=y)
        {
            add(x,y);
            ++d[y];
        }
    }
    
    queue<int>q;    
    inc(i,1,col)if(!d[i])
    {
        ++cnt;
        q.push(i);
    }
    
    while(!q.empty())
    {
        if(cnt>1)re 1;
        int u=q.front();
        --cnt;
        q.pop();
        for(int i=hd[u];i;i=e[i].nt)
        {
            int v=e[i].to;
            --d[v];
            if(!d[v])
            {
                ++cnt;
                q.push(v);
            }
        }
    }
    re 0;    
}

int main()
{
    
    //freopen("in.txt","r",stdin);
    rd(T);
    while(T--)
    {
        rd(n),rd(m);
        k=tot=col=0;
        inc(i,1,n)
        {
            dfn[i]=low[i]=belong[i]=0;
            d[i]=to[i]=fr[i]=hd[i]=0;
            fa[i]=i;    
        }
        
        int x,y;
        inc(i,1,m)
        {
            rd(x),rd(y);
            add(x,y);
        }
        
        
        inc(i,1,n)
        if(!dfn[i])
            tarjan(i);
        
        
        if(topo())printf("Light my fire!\n");
        else printf("I love you my love and our love save us!\n");
    }
    re 0;
} 

Two, maple do the math

Description [title]

One day, the maple math class, he learned how to ask a number of factors, so the teacher arranged for him a question, in the interval [L, R] inside, to find all the following conditions are met figures: the number of second small factor K. After find these figures, maple but also to all the numbers add up, may I ask what the end result is?

[Input Format]

Only one line of input data, three numbers L, R, K meanings as described in the subject shown in

[Output format]

An integer representing the number of these add and how much, the answer mode MOD . 1 E . 9 + . 7 mod1e9 +. 7

[1] Sample input

1 20 5

[1] Sample Output

5

Sample 2 [Enter]

2 6 3

[2] Sample Output

3

[Data] Conventions

20% of the data . 1 L R & lt 10 ^ . 5 , 2 K 10 ^ . 5 1≤L≤R≤10 ^ ^. 5 5,2≤K≤10

100% of the data . 1 L R & lt 10 ^ . 11 , 2 K 10 ^ . 11 1≤L≤R≤10 ^ ^. 11 11,2≤K≤10


 

Mathematics slag like me:

Hey, mathematics eh!

Thinking 1min ......

Do not, absolutely can not do

I looked at the third question, but also a level Gu Lala membrane title: Mathematics

Violence, violence ~~~

Explosion zero, zero burst ~ ~ ~

However, strong LL success Gou to 60pts (flowers, applause)

The correct answer (dp)

#include<bits/stdc++.h>
#define re return
#define ll long long
#define inc(i,l,r) for(int i=l;i<=r;++i)

using namespace std;
template<typename T>inline void rd(T&x)
{
    char c;bool f=0;
    while((c=getchar())<'0'||c>'9')if(c=='-')f=1;
    x=c^48;
    while((c=getchar())>='0'&&c<='9')x=x*10+(c^48);
    if(f)x=-x;
}

const int maxn=16000005,NN=10010,MM=120;
const ll mod=1e9+7;

ll L,R,K,dp[NN][MM];
ll cnt,notprime[320005],prime[320005];

inline bool isprime(ll x)
{
    if(x%2==0&&x!=2)re 0;
    for(int i=3;i<=sqrt(x);i+=2)
    if(!(x%i))re 0;
    re 1;
}

inline void Get_prime()//得到质数 
{
    notprime[1]=1;
    inc(i,2,K)
    {
        if(!notprime[i])
        prime[++cnt]=i;
        
        inc(j,1,cnt)
        {
            if(prime[j]*i>K)break;
            notprime [Prime [J] * I] = Prime [J];
             IF ((I% Prime [J])!) BREAK ; 
        } 
    } 
} 


inline LL F. (n-LL, LL m) 
// F. (n-, m) a front i number, before removing the m prime numbers and 
{ 
    LL ANS; 
    IF (n-<NN && m <the MM && DP [n-] [m]) Re DP [n-] [m]; // memory of 
    the else  IF (n-< 2 ) = n-ANS; // 0,1 not any positive integer multiple of the number of quality level 
    the else  IF (! m) ANS = (( . 1 + n-) MOD%) * (n-% MOD) MOD *% 500 000 004 % MOD;
     // i.e. the first n and the number of seek, the arithmetic series
     // because modulo divider is not set up, by which it is converted to (2) an inverse element (500,000,004)
    the else  IF (Prime [m]> n-) 
    { 
        the while (m && Prime [m]> n-) - m;
         // Prime [m]> n-meaningless
         // simplified 
        ANS = F. (n-, m); 
    } 
    the else ANS = (F. (n-, M- . 1 ) -prime [m] * (n-/ Prime [m] F., M- . 1 ) MOD% MOD +)% MOD;
     // key: for (n / prime [m]) , For example, two times 5,5, and 3 times 5 are not satisfied 
    IF (n-<&& m NN <the MM) DP [n-] [m] = ANS; // memory of 
    Re ANS; 
} 

int main () 
{ 
    RD (L), RD (R & lt), RD (K); 
    
    IF the printf ((isPrime (K)!) " 0 " );
    // If K is not a prime number, it is definitely not a multiple of times smaller factor K 
    the else  IF (sqrt (R & lt) < K) 
    { 
    // when K is 1 ~ R can be at most a Gou i.e. (K) 
        IF (R & lt> = K && K> = L) the printf ( " % LLD " , K% MOD);
         the else the printf ( " 0 " ); 
    } 
    the else  
    { 
        Get_prime (); // get all primes less than K of 
        the printf ( " % LLD " , (F. (R & lt / K, the CNT- . 1 ) MOD *% K-F. ((L- . 1 ) / K, the CNT- . 1 ) * K + MOD% MOD)% MOD); 
    } 

    Re 0 ; 
}

 

Third, digital

Description [title]

There is a list of n numbers, you can perform two operations on the list

1. Delete a number with the cost of x

2. Select a number with the cost of an increase of y

Two operations is no limit, ask this list so that all the numbers gcd (greatest common factor) is greater than the minimum cost of 1 how much?

[Input Format]

The first three rows represent integers n, x, y.

The second row has n represents an integer number of the list.

[Output format]

An integer that represents the minimum cost.

[1] Sample input

4 23 17
1 17 17 16

[1] Sample Output

40

Sample 2 [Enter]

10 6 2
100 49 71 73 66 96 8 60 41 63

[2] Sample Output

10

[Data] Conventions

For 30% of the data 1 <= n <= 1000

Data for 100% 1 <= n <= 500000, 1 <= x, y <= 1000000000, 1 <= a [i] <= 1000000


 

Suddenly understand why I was wrong this morning ......

In fact, since the data over the water, gcd only within 50 Enumeration

Sad, rain Chopin

Cheat points Dafa

on

#include<bits/stdc++.h>
#define re return
#define ll long long
#define inc(i,l,r) for(register int i=l;i<=r;++i)

using namespace std;
template<typename T>inline void rd(T&x)
{
    char c;bool f=0;
    while((c=getchar())<'0'||c>'9')if(c=='-')f=1;
    x=c^48;
    while((c=getchar())>='0'&&c<='9')x=x*10+(c^48);
    if(f)x=-x;
}

int prime[100005],notprime[1000005];
int n,maxx,cnt,a[500005];

inline void Get_prime()
{
    notprime[1]=1;
    inc(i,2,50)
    {
        if(!notprime[i])
        prime[++cnt]=i;
        inc(j,1,cnt)
        {
            if(prime[j]*i>50)break;
            notprime[prime[j]*i]=prime[j];
            if(i%prime[j])break;
        }
    }
}

int main()
{
    int cx,cy;
    rd(n),rd(cx),rd(cy);
    
    inc(i,1,n)
    {
        rd(a[i]);
        maxx=a[i]>maxx?a[i]:maxx;
    }
    
    ll ans=99999999999999999;
    Get_prime();//Obtained within 50 prime factor 
    inc is (C, . 1 , 15 ) // a total of 16 
    {
         int I = Prime [C]; 
        LL nowans = 0 ; 
        inc is (J, . 1 , n-) 
        { 
            LL T = A [J]% i;
                 IF (t) = t (IT) * (LL) CY; // to a multiple of at least i would also like to IT;
                         // need cy * (it) costs 
                nowans + = CX <CX t: t;? // Comparative take minimum 
            IF (nowans> ANS) BREAK ; // pruning 
        } 
        ANS? ANS = <nowans ANS: nowans; 
    } 
    // violence enumeration 
    printf ( " % LLD " , ANS); 
    Re 0 ; 
}
    

 

Guess you like

Origin www.cnblogs.com/lsyyy/p/11440362.html