Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)

来源:互联网 发布:c语言temp怎么定义 编辑:程序博客网 时间:2024/06/08 11:55

这次的CF  A题有种很特别的解题思路  所以PO上来

A. Slime Combining
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.

You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the othern - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same valuev, you combine them together to create a slime with valuev + 1.

You would like to see what the final state of the row is after you've added alln slimes. Please print the values of the slimes in the row from left to right.

Input

The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).

Output

Output a single line with k integers, wherek is the number of slimes in the row after you've finished the procedure described in the problem statement. Thei-th of these numbers should be the value of thei-th slime from the left.


我的解题思路是用递归来写 这是我的代码:

#include<stdio.h>__int64 x[100005],y[100005];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        int i;        for(i=1;i<=n;i++)        {            scanf("%I64d%I64d",&x[i],&y[i]);        }        __int64 minnum=9223372036854775807;        int ans1=0;        double jiaodu;        for(i=2;i<=n;i++)        {            __int64 flag=(x[i]-x[1])*(x[i]-x[1]) +(y[i]-y[1])*(y[i]-y[1]);            if( flag<minnum )            {                jiaodu=(1.0*(y[i]-y[1]))/(1.0*(x[i]-x[1]));                ans1=i;                minnum=flag;            }        }        int ans2=0;        double jiaodu2;        minnum=9223372036854775807;        for(i=2;i<=n;i++)        {            if(i==ans1)                continue;            __int64 flag=(x[i]-x[1])*(x[i]-x[1]) +(y[i]-y[1])*(y[i]-y[1]);            jiaodu2=(1.0*(y[i]-y[1]))/(1.0*(x[i]-x[1]));            if( flag<minnum &&(jiaodu2!=jiaodu) )            {                ans2=i;                minnum=flag;            }        }        printf("%d %d %d\n",1,ans1,ans2);    }    return 0;}



然后候看到一个很好的代码  ,答案可用二进制表示:

#include <bits/stdc++.h>using namespace std;int main(){    int n;    scanf("%d", &n);    for (int i = 20; i >= 0; i--)        if (n&(1<<i))   printf("%d ", i+1);    return 0;}



机智的小伙伴~



顺便po下B ,C:

B. Guess the Permutation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Bob has a permutation of integers from 1 to n. Denote this permutation as p. Thei-th element ofp will be denoted aspi. For all pairs of distinct integersi, j between1 and n, he wrote the numberai, j = min(pi, pj). He writesai, i = 0 for all integeri from 1 to n.

Bob gave you all the values of ai, j that he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given.

Input

The first line of the input will contain a single integer n (2 ≤ n ≤ 50).

The next n lines will contain the values ofai, j. Thej-th number on thei-th line will represent ai, j. Thei-th number on thei-th line will be 0. It's guaranteed thatai, j = aj, i and there is at least one solution consistent with the information given.

Output

Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.


#include<stdio.h>#include<stdlib.h>#include<string.h>int data[60][60];int ans[60];int use[60];int main (){    int n;    while(scanf("%d",&n)!=EOF)    {        int i,j;        for(i=1;i<=n;i++)            for(j=1;j<=n;j++)            scanf("%d",&data[i][j]);        memset(use,0,sizeof(use));        for(i=1;i<=n;i++)        {            for(j=1;j<=n;j++)            {                if(use[j])                    continue;                int flag=0;                int k;                for(k=1;k<=n;k++)                {                    if(data[j][k]!=i&&data[j][k]!=0)                    {                        flag=1;                        break;                    }                }                if(flag==0)                {                    ans[j]=i;                    use[j]=1;                    for(int z=1;z<=n;z++)                        data[z][j]=0;                        break;                }            }        }        for(i=1;i<=n;i++)        {            printf("%d%c",ans[i],i==n?'\n':' ');        }    }        return 0;}



C:

C. Constellation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Cat Noku has obtained a map of the night sky. On this map, he found a constellation withn stars numbered from1 to n. For eachi, the i-th star is located at coordinates(xi, yi). No two stars are located at the same position.

In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.

It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.

Input

The first line of the input contains a single integer n (3 ≤ n ≤ 100 000).

Each of the next n lines contains two integersxi andyi ( - 109 ≤ xi, yi ≤ 109).

It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.

Output

Print three distinct integers on a single line — the indices of the three points that form a triangle that satisfies the conditions stated in the problem.

If there are multiple possible answers, you may print any of them.


#include<stdio.h>__int64 x[100005],y[100005];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        int i;        for(i=1;i<=n;i++)        {            scanf("%I64d%I64d",&x[i],&y[i]);        }        __int64 minnum=9223372036854775807;        int ans1=0;        double jiaodu;        for(i=2;i<=n;i++)        {            __int64 flag=(x[i]-x[1])*(x[i]-x[1]) +(y[i]-y[1])*(y[i]-y[1]);            if( flag<minnum )            {                jiaodu=(1.0*(y[i]-y[1]))/(1.0*(x[i]-x[1]));                ans1=i;                minnum=flag;            }        }        int ans2=0;        double jiaodu2;        minnum=9223372036854775807;        for(i=2;i<=n;i++)        {            if(i==ans1)                continue;            __int64 flag=(x[i]-x[1])*(x[i]-x[1]) +(y[i]-y[1])*(y[i]-y[1]);            jiaodu2=(1.0*(y[i]-y[1]))/(1.0*(x[i]-x[1]));            if( flag<minnum &&(jiaodu2!=jiaodu) )            {                ans2=i;                minnum=flag;            }        }        printf("%d %d %d\n",1,ans1,ans2);    }    return 0;}


c题只要找出不共线的、距离最近的三个点;

证明过可行性,也发现了别人的其他方法;

0 0
原创粉丝点击