2016/04/09练习赛(三)



  练习赛晚去了40Min,还提前走了1H,hahhahahha。

                 J - A Computer Graphics Problem HDU 4716

                                                                    Time Limit: 1000 MS Memory Limit: 32768 KB    

Description

In this problem we talk about the study of Computer Graphics. Of course, this is very, very hard.
We have designed a new mobile phone, your task is to write a interface to display battery powers.
Here we use '.' as empty grids.
When the battery is empty, the interface will look like this:
*------------*
|............|
|............|
|............|
|............|
|............|
|............|
|............|
|............|
|............|
|............|
*------------*

When the battery is 60% full, the interface will look like this:
*------------*
|............|
|............|
|............|
|............|
|------------|
|------------|
|------------|
|------------|
|------------|
|------------|
*------------*

Each line there are 14 characters.
Given the battery power the mobile phone left, say x%, your task is to output the corresponding interface. Here x will always be a multiple of 10, and never exceeds 100.

Input

The first line has a number T (T < 10) , indicating the number of test cases.
For each test case there is a single line with a number x. (0 < x < 100, x is a multiple of 10)

Output

For test case X, output "Case #X:" at the first line. Then output the corresponding interface.
See sample output for more details.

Sample Input

2
0
60

Sample Output

Case #1:
*------------*
|............|
|............|
|............|
|............|
|............|
|............|
|............|
|............|
|............|
|............|
*------------*
Case #2:
*------------*
|............|
|............|
|............|
|............|
|------------|
|------------|
|------------|
|------------|
|------------|
|------------|
*------------*
题解:图形输出,模拟电池。简单题83Min1Y.
代码:
#include <iostream>
#include <stdio.h>
using namespace std;
char b[2][20]={"|............|","|------------|"};
char c[20]={"*------------*"};
int main()
{
    int t,a;
    cin>>t;
    int k=0;
    while(t--)
    {
        k++;
        cin>>a;
        printf("Case #%d:\n",k);
        int bb=a/10;
        cout<<c<<endl;
        for(int i=1;i<=10-bb;i++)
        {
            cout<<b[0]<<endl;

        }
        for(int i=10-bb;i<10;i++)
        {
            cout<<b[1]<<endl;
        }
         cout<<c<<endl;
    }
}
 
   

G - I Wanna Go Home POJ 3767

Time Limit: 1000 MS Memory Limit: 65536 KB

Description

The country is facing a terrible civil war----cities in the country are divided into two parts supporting different leaders. As a merchant, Mr. M does not pay attention to politics but he actually knows the severe situation, and your task is to help him reach home as soon as possible.

"For the sake of safety,", said Mr.M, "your route should contain at most 1 road which connects two cities of different camp."

Would you please tell Mr. M at least how long will it take to reach his sweet home?

Input

The input contains multiple test cases.

The first line of each case is an integer N (2<=N<=600), representing the number of cities in the country.

The second line contains one integer M (0<=M<=10000), which is the number of roads.

The following M lines are the information of the roads. Each line contains three integers A, B and T, which means the road between city A and city B will cost time T. T is in the range of [1,500].

Next part contains N integers, which are either 1 or 2. The i-th integer shows the supporting leader of city i.

To simplify the problem, we assume that Mr. M starts from city 1 and his target is city 2. City 1 always supports leader 1 while city 2 is at the same side of leader 2.

Note that all roads are bidirectional and there is at most 1 road between two cities.

Input is ended with a case of N=0.

Output

For each test case, output one integer representing the minimum time to reach home.

If it is impossible to reach home according to Mr. M's demands, output -1 instead.

Sample Input

2
1
1 2 100
1 2
3
3
1 2 100
1 3 40
2 3 50
1 2 1
5
5
3 1 200
5 3 150
2 5 160
4 3 170
4 2 170
1 2 2 2 1
0

Sample Output

100
90
540
题意:
N个城市M条路,后M行为城市ab之间有路,花费为c,
最后一行为每个城市隶属的势力,
另外,至多只能走一条连接不同势力的路(L)。
问从城市1到城市2的最小花费。
题解:
因为默认城市1,2属于不同的势力,所以L只能是从势力1到势力2的路,
然后dij跑一下就好了.133Min1Y
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int INF=100000;
int a,b;
int c[605];
int d[605];
int map[605][605];
int vis[605];
int dij()
{
    int v;
    for(int i=1;i<=a;i++)
        d[i]=map[1][i];
        d[1]=0;
        vis[1]=1;
        for(int i=1;i<a;i++)
        {
            int mi=INF;
            v=1;
            for(int j=1;j<=a;j++)
            {
                if(!vis[j]&&mi>d[j])
                {
                    mi=d[j];
                      v=j;
                }
            }
            vis[v]=1;
            if(v==2)
                break;
            for(int j=1;j<=a;j++)
            {
                if(!vis[j]&&d[j]>d[v]+map[v][j])
                {
                    d[j]=d[v]+map[v][j];
                }
            }
        }
        if(d[2]>=INF)
            return -1;
        else
        return d[2];
}
int main()
{
    while(cin>>a)
    {
         if(a==0)
            break;
      for(int i=1;i<=a;i++)
      {
          for(int j=1;j<=a;j++)
          {
              map[i][j]=map[j][i]=INF;
          }
      }
        memset(c,0,sizeof(c));
        memset(vis,0,sizeof(vis));
        cin>>b;
        int b1,b2,b3;
        for(int i=0;i<b;i++)
        {
            cin>>b1>>b2>>b3;
            map[b1][b2]=b3;
            map[b2][b1]=b3;
        }
        for(int i=1;i<=a;i++)
        {
            cin>>c[i];
        }
        for(int i=1;i<=a;++i)
        {
            for(int j=1;j<=a;++j)//将这种从势力2到势力1的路设为无穷大。
            {
                if(c[i]!=c[j])
                {
                    if(c[i]==1)
                        map[j][i]=INF;
                    else
                        map[i][j]=INF;
                }
            }
        }
        cout<<dij()<<endl;
    }
}

I - Difference Between Primes HDU 4715

Time Limit: 1000 MS Memory Limit: 32768 KB

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
题意:
在素数中找到差为x的数a和b,并且a得是满足这种情况的最大值。156Min2Y。
题解:
打一个素数表。用set存,从小到大枚举b,则a=b+x,判断a在不在set内
代码:
#include<stdio.h>
#include <set>
#include <iostream>
using namespace std;
int a[2000001]= {1,1};
set<int>b;
int bb[153000];
int main()
{
    int i,j,k=0;
    for(i=2; i<=2000000; i++)
    {
        if(!a[i])
        {
            b.insert(i);
            bb[k++]=i;
            for(j=2; i*j<=2000000; j++)
            {
                a[i*j]=1;
            }
        }
    }
    int x,y,t,n;
    scanf("%d",&t);
    while(t--)
    {
        int flag=0;
        scanf("%d",&n);
        for(x=0; x<153000; x++)
        {
            int t=bb[x]+n;
            if(b.count(t))
            {
                printf("%d %d\n",t,bb[x]);
                flag=1;
                break;
            }
        }
        if(!flag)
            cout<<"FAIL"<<endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值