现在的位置: 首页 > 综合 > 正文

2013网赛热身赛几道水题

2013年11月03日 ⁄ 综合 ⁄ 共 6679字 ⁄ 字号 评论关闭

Children's Day

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 239    Accepted Submission(s): 138


Problem Description
Today is Children's Day. Some children ask you to output a big letter 'N'. 'N' is constituted by two vertical linesand one diagonal. Each pixel of this letter is a character orderly. No tail blank is allowed.
For example, this is a big 'N' start with 'a' and it's size is 3.
a e
bdf
c g

Your task is to write different 'N' from size 3 to size 10. The pixel character used is from 'a' to 'z' continuously and periodic('a' is reused after 'z').

 


Input
This problem has no input.
 


Output
Output different 'N' from size 3 to size 10. There is no blank line among output.
 


Sample Output
[pre] a e bdf c g h n i mo jl p k q ......... r j [/pre]
Hint
Not all the resultsare listed in the sample. There are just some lines. The ellipsis expresseswhat you should write.
 


Source
 
题目大意:看输出就知道了,没有输入的简单模拟水题。

         题目地址:Children's Day

AC代码:
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
char a[12][12];

int main()
{
    int i,j,k;
    a[0][0]='a';
    a[0][1]=' ';
    a[0][2]='e';
    a[0][3]='\0';
    a[1][0]='b';
    a[1][1]='d';
    a[1][2]='f';
    a[1][3]='\0';
    a[2][0]='c';
    a[2][1]=' ';
    a[2][2]='g';
    a[2][3]='\0';
    cout<<a[0]<<endl;
    cout<<a[1]<<endl;
    cout<<a[2]<<endl;
    for(i=3;i<10;i++)
    {
        char p=a[i-1][i-1];
        for(j=0;j<=i;j++)
            for(k=0;k<=i;k++)
               a[j][k]=' ';
        a[0][0]=p+1;
        if(a[0][0]>'z')
            a[0][0]='a';
        for(j=1;j<=i;j++)
        {
            a[j][0]=a[j-1][0]+1;
            if(a[j][0]>'z')
              a[j][0]='a';
        }
        for(j=i-1;j>=0;j--)
        {
            a[j][i-j]=a[j+1][i-j-1]+1;
            if(a[j][i-j]>'z')
               a[j][i-j]='a';
        }
        for(j=1;j<=i;j++)
        {
            a[j][i]=a[j-1][i]+1;
            if(a[j][i]>'z')
              a[j][i]='a';
        }
        for(j=0;j<=i;j++)
            a[j][i+1]='\0';
        for(j=0;j<=i;j++)
            cout<<a[j]<<endl;
    }
    return 0;
}

Herding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 575    Accepted Submission(s): 128


Problem Description
Little John is herding his father's cattles. As a lazy boy, he cannot tolerate chasing the cattles all the time to avoid unnecessary omission. Luckily, he notice that there were N trees in the meadow numbered from 1 to N, and calculated their cartesian coordinates
(Xi, Yi). To herding his cattles safely, the easiest way is to connect some of the trees (with different numbers, of course) with fences, and the close region they formed would be herding area. Little John wants the area of this region to be as small as possible,
and it could not be zero, of course.
 


Input
The first line contains the number of test cases T( T<=25 ). Following lines are the scenarios of each test case.
The first line of each test case contains one integer N( 1<=N<=100 ). The following N lines describe the coordinates of the trees. Each of these lines will contain two float numbers Xi and Yi( -1000<=Xi, Yi<=1000 ) representing the coordinates of the corresponding
tree. The coordinates of the trees will not coincide with each other.
 


Output
For each test case, please output one number rounded to 2 digits after the decimal point representing the area of the smallest region. Or output "Impossible"(without quotations), if it do not exists such a region.
 


Sample Input
1 4 -1.00 0.00 0.00 -3.00 2.00 0.00 2.00 2.00
 


Sample Output
2.00
 


Source
 

         题目大意:很多点,找能围成的最小面积,肯定是三角形啊。没有的话需要输出Impossible。只需要判断三点共线即可。


         题目地址:Herding

AC代码:
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
double a[105],b[105];
double eps=0.0000000001;

int main()
{
    int tes,n,i,j,k;
    scanf("%d",&tes);
    while(tes--)
    {
        scanf("%d",&n);
        for(i=0;i<n;i++)
            scanf("%lf%lf",&a[i],&b[i]);

        double res=1000000000;  //初始化最大面积
        for(i=0;i<n;i++)
            for(j=i+1;j<n;j++)
              for(k=j+1;k<n;k++)
              {
                   double x1,y1,x2,y2,x3,y3;
                   x1=a[i],y1=b[i],x2=a[j],y2=b[j],x3=a[k],y3=b[k];
                   if(abs((y3-y2)*(x2-x1)-(y2-y1)*(x3-x2))>eps)
                   {
                      double a,b,c,p;   //海伦公式求三角形的面积
                      a=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
                      b=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
                      c=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
                      p=(a+b+c)/2.0;
                      double tmp=sqrt(p*(p-a)*(p-b)*(p-c));
                      if(tmp<res)
                        res=tmp;
                   }
              }
        if(res==1000000000)
            cout<<"Impossible"<<endl;
        else
            printf("%.2f\n",res);
    }
    return 0;
}

Balls Rearrangement

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 196    Accepted Submission(s): 93


Problem Description
Bob has N balls and A boxes. He numbers the balls from 0 to N-1, and numbers the boxes from 0 to A-1. To find the balls easily, he puts the ball numbered x into the box numbered a if x = a mod A.
Some day Bob buys B new boxes, and he wants to rearrange the balls from the old boxes to the new boxes. The new boxes are numbered from 0 to B-1. After the rearrangement, the ball numbered x should be in the box number b if x = b mod B.
This work may be very boring, so he wants to know the cost before the rearrangement. If he moves a ball from the old box numbered a to the new box numbered b, the cost he considered would be |a-b|. The total cost is the sum of the cost to move every ball, and
it is what Bob is interested in now.
 


Input
The first line of the input is an integer T, the number of test cases.(0<T<=50)
Then T test case followed. The only line of each test case are three integers N, A and B.(1<=N<=1000000000, 1<=A,B<=100000).
 


Output
For each test case, output the total cost.
 


Sample Input
3 1000000000 1 1 8 2 4 11 5 3
 


Sample Output
0 8 16
 


Source
 

先前自己A的一道原题啊,可以博客:HDU 4611Balls Rearrangement(思维)

Difference Between Primes

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 561    Accepted Submission(s): 170


Problem Description
All you know Goldbach conjecture.That is to say, Every even integer greater than 2 can be expressed as the sum of two primes. Today, skywind present a new conjecture: every even integer can be expressed as the difference of two primes. To validate this conjecture,
you are asked to write a program.
 


Input
The first line of input is a number nidentified the count of test cases(n<10^5). There is a even number xat the next nlines. The absolute value of xis not greater than 10^6.
 


Output
For each number xtested, outputstwo primes aand bat one line separatedwith one space where a-b=x. If more than one group can meet it, output the minimum group. If no primes can satisfy it, output 'FAIL'.
 


Sample Input
3 6 10 20
 


Sample Output
11 5 13 3 23 3
 


Source
 

题目大意:意思很简单,给你个x,找两个素数使得差值是x。当时就在写暴力解法。不过没看清楚x还可以是负的,敲代码页没他们快。具体见代码。

         题目地址:Difference Between Primes

AC代码:
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int M=10000;
int mark[M];
int prim[M];
void sxprime()
{
    memset(mark,1,sizeof(mark));
    mark[0]=mark[1]=0;
    for(int i=2; i<=sqrt((double)M); i++)
    {
        if(mark[i])
        {
            for(int j=i*i; j<M; j+=i)
                mark[j]=0;
        }
    }
}

bool isprim(int u)
{
    if(u==0||u==1) return false;
    if(u==2) return true;
    if(u%2==0) return false;
    for(int i=3; i<=sqrt((double)u); i+=2)
        if(u%i==0)
            return false;
    return true;
}

int main()
{
    int i,tes;
    int p=0,x;
    sxprime();
    for(i=1; i<=M; i++)
    {
        if(mark[i])
            prim[p++]=i;
    }
    scanf("%d",&tes);

    while(tes--)
    {
        scanf("%d",&x);
        int flag=0;

        if(x==0)
        {
            cout<<"2 2"<<endl;
            continue;
        }
        if(x>0)
        {
            for(i=0; i<p; i++)
                if(isprim(x+prim[i]))
                {
                    cout<<x+prim[i]<<" "<<prim[i]<<endl;
                    flag=1;
                    break;
                }
            if(flag==0)
                cout<<"FAIL"<<endl;
        }
        else
        {
            x=-x;
            for(i=0; i<p; i++)
                if(isprim(x+prim[i]))
                {
                    cout<<prim[i]<<" "<<x+prim[i]<<endl;
                    flag=1;
                    break;
                }
            if(flag==0)
                cout<<"FAIL"<<endl;
        }
    }
    return 0;
}

抱歉!评论已关闭.