8.15 discipline in training Day15

T1 [3] Kurt exam NOIP2013 analog vector (code)

Description

In the past a beautiful campus, there is a (trees) lovely curved tree branch manager. She introverted and shy, a weak gas way people wanted to see a good love her. Only her side, and there are many girls want her BH, such as bell, Kurt, and so on. However, Gorges cloud, tree psychological reason only that the tall handsome boy - Kyosuke, which makes the girls had to moan and groan all day, in tears. But Kyosuke is so powerful and perfect, there is no way to defeat him, they also had to bite the pain to get by, pending the counter when the.

Finally, they get an opportunity. Kute Li wit with ballistics, cryptography, knowledge of cosmology designed a chamber that allows people to enter the export can not be opened from the inside. Kurt password design process is wonderful, n-dimensional vector is represented by two with integer coordinates derived. Amazingly, for any one of these two vectors, the coordinates of which in any event will disrupt (e.g., (a1, a2, a3) into (a3, a1, a2)) , the number of the product is not disrupted It will be smaller than the number of the original product of two vectors. Kurt put the original and the number of two vectors as a password. Now they only put Kyosuke introduced it. However, sometime because of their carelessness, at the time of the test chamber to accidentally shut themselves inside, but also took away the password of paper. Bell only found out after the draft was written two vector disrupted Kurt. Wow ~ call can save these adorable sister, to see you.

Input

Three lines. A first line integer N, the N-dimensional.

N integers each line 2 to line 3, after the two vectors represents disrupted (a1, a2, a3, a4 ... an), (b1, b2, b3, b4 ... bn).

Output

The questions asked, the password output design Kurt

Sample Input

3
1 3 -5
-2 4 1

Sample Output

-25

Data Constraint

50% of the data for n <= 8, | ai | , | bi | <= 1000

to 100% of the data n <= 1000, | ai | , | bi | <= 100000

Examination room ideas / positive solution

Face it very profound question, the harm I did not understand just started doing. In fact, this problem is sorted inequality gone.

Code

#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;

LL n,ans;
LL a[1010],b[1010];

bool cmp(LL a,LL b)
<%return a>b;%>

int main()
{
    scanf("%lld",&n);
    for(LL i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    for(LL i=1;i<=n;i++)
        scanf("%lld",&b[i]);
    sort(a+1,a+1+n);
    sort(b+1,b+1+n,cmp);
    for(LL i=1;i<=n;i++)
        ans+=(a[i]*b[i]);
    printf("%lld",ans);
    return 0;
}

T2 [3] NOIP2013 analog exam Kyosuke rule (rule) 

Description

Finally, in all the parents who struggle, Kyosuke final boss was locked up in Kut design of the chamber. Just when they are relieved that the world has undergone a capsized days to change: the ground began to sink, the sky began to turn blood red, the water boil ...... an apocalyptic picture. US Fish from her hands the ancient "Bokusui Wakayama poetry collection" found the reason: Shiratori wa ka na kara zu shi ya Qinghai empty の の thou wo ni mo ta da yo dye ma zu fu. Large (xia) Italy (shuo) Kyosuke is cunning in creating this world when he tampered with the law. The origin of this rule is that a cat between life and death. The cat was kept in a black box, the box has two gas canisters, if there is any one gas tank is open so the cat will be killed, the law can be corrected. However, the outside world can only control the probability of two gas canisters were opened. Assume that the probability of a gas canister is opened is 1 / x, the second canisters as 1 / y (x, y is a positive integer), and then when the two probabilities is 1 / (n!), The cat They are inexplicably killed. Now the US Fish would like to know how many of the (x, y) can somehow let the cat was killed.

Input

Line, a positive integer n

Output

Line to meet the meaning of the title (x, y) pairs.

Sample Input

6

Sample Output

135

Data Constraint

30% of the data for n <= 6

to 60% of the data n <= 50

to 100% of the data n <= 700000

Examination room ideas

The first moment is ignorant, after all, this is a math, so I can only hit the table of the violence.

Correct

Simplify the problem, it is to compute the (n-!) 2 prime factor. Then it ended quickly and happily.

Code

#include<cstdio>
#include<algorithm>
#define LL long long
#define Mod 100000000
using namespace std;

LL n,len,zx,zhi,jl;
LL ans[50050],book[700070];

void Mul(LL x)
{
    for(LL i=1;i<=len;i++)
        ans[i]*=x;
    for(LL i=1;i<=len;i++)
    {
        ans[i+1]+=ans[i]/Mod;
        ans[i]%=Mod;
    }
    while(ans[len+1]>0)
    {
        len++;
        ans[len+1]+=ans[len]/Mod;
        ans[len]%=Mod;
        
    }
}

int main()
{
    scanf("%lld",&n);
    ans[1]=1;len=1;jl=1;
    for(LL i=2;i<=n;i++)
    {
        if(book[i])
            continue;
        zx=n,zhi=0;
        while(zx>=i)
            zx/=i,zhi+=zx;
        zhi=zhi*2+1;
        if(zhi*jl>Mod)
            Mul(jl),jl=1;
        jl*=zhi;
        for(LL j=i;j<=n;j+=i)
            book[j]=1;
    }
    if(jl>1)
        Mul(jl);
    printf("%lld",ans[len]);
    for(LL i=len-1;i>=1;i--)
        printf("%08lld",ans[i]);
    return 0;
}

T3 [3] Saya NOIP2013 analog exam doll (Doll) 

Description

While the US Fish and Riki back-up group to save the world, looks weak rationale for the tree began to be strong and think of a way to leave this world. Cock, she met the classroom was destroyed entrance to the maze of desks open Shaye. Shaye told the management tree, world exports is the export of this maze. So Riki did not hesitate to jump into the maze together with Shaye. In the maze, two girls help each other, while cutting the rope, while hot springs, while carving ice, stumbled come to an end. Not surprisingly, there is also an organ at the end waiting for them.

The end is a standing organ of m * n chessboard squares, put a doll on some lattice, and some places directly dug a pit. Only take away all the dolls in order to open the exit. However, due to the strange setting, Riki and Shaye not directly touch the dolls, they need to manipulate the robot to collect it. The robot moves very strange, and a bit like a chess horse, but the horse can go in any direction 1 * 2 route, they will only go r * c (or c * r) line from top to bottom, can not go back . Once the robot through a lattice doll, the doll on the grid that will be recycled, and when the robot left, the grid will become a pit. Riki can put a robot on the grid have any dolls as a starting point, you can also have a doll collection robot in any grid. Walking robot can be regarded as teleport, but every time to set a new starting point will consume 1 time. Also, there can not be settled in the pit of the grid.

At this critical juncture, but Saya doll enthusiasts drooling IQ return 0. Riki had to turn to you for help, help calculate the minimum amount of time will be able to collect all the dolls.

Input

The first row contains four integers M, N, R, C, see the problem described meaning. Next M lines each a length of N

strings. If a character that represents this place has a doll. ''; If this character is 'x', to represent this

party is the pits.

Output

Output an integer, represents the shortest time.

Sample Input

3 3 1 2
...
.x.
...

Sample Output

4

Data Constraint

30% of the data, 1 <= M, N < = 4,1 <= R, C <= 3.

70% of the data, 1 <= M <= 20,1 <= N <= 4,1 <= R, C <= 3.

100% of the data, 1 <= M, N < = 50,1 <= R, C <= 10.

Hint

Examination room ideas / positive solution

Careful observation, or in fact, this problem is found bipartite graph matching, really naked.

Code

#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define Ud unsigned
using namespace std;

int m,n,r,c,sum1,sum2;
int used[5050],vis[5050];
Ud len[5050];
char tu[55][55];
vector<int> rel[5050];

void Work(int x,int y)
{
    int x1=x+r,x2=x+c,y1=y+r,y2=y+c,y3=y-r,y4=y-c;
    if(x1>0 && y2>0 && x1<=m && y2<=n && tu[x1][y2]=='.')
        rel[(x-1)*n+y].push_back((x1-1)*n+y2);
    if(x1>0 && y4>0 && x1<=m && y4<=n && tu[x1][y4]=='.')
        rel[(x-1)*n+y].push_back((x1-1)*n+y4);
    if(x2>0 && y1>0 && x2<=m && y1<=n && tu[x2][y1]=='.')
        rel[(x-1)*n+y].push_back((x2-1)*n+y1);
    if(x2>0 && y3>0 && x2<=m && y3<=n && tu[x2][y3]=='.')
        rel[(x-1)*n+y].push_back((x2-1)*n+y3);
}

bool dfs(int x)
{
    for(Ud i=0;i<len[x];i++)
        if(!vis[rel[x][i]])
        {
            vis[rel[x][i]]=1;
            if(!used[rel[x][i]] || dfs(used[rel[x][i]]))
            {
                used[rel[x][i]]=x;
                return true;
            }
        }
    return false;
}

int main()
{
    scanf("%d%d%d%d",&m,&n,&r,&c);
    for(int i=1;i<=m;i++)
        scanf("%s",tu[i]+1);
    for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++)
            if(tu[i][j]=='.')
                sum1++;
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(tu[i][j]!='.')
                continue;
            Work(i,j);
        }
    }
    for(int i=1;i<=n*m;i++)
        len[i]=rel[i].size();
    for(int i=1;i<=n*m;i++)
    {
        memset(vis,0,sizeof(vis));
        if(dfs(i))
            sum2++;
    }
    printf("%d",sum1-sum2);
    return 0;
}

to sum up

Today managed to get it count fortunately, very pleasant T1 and T2 A, so very happy today rank3 up. Ha ha ha!

Left 85 days from NOIp2019 Festival

Guess you like

Origin www.cnblogs.com/Thm-V/p/11360891.html