码迷,mamicode.com
首页 > 其他好文 > 详细

周赛2(星期三之前补题完)

时间:2017-06-10 13:49:04      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:uil   case   sts   center   otto   efi   mis   rmi   1.2   

本厂做了3个水体,被略哭

水题1  暴力乱搞

题目:

回文数猜想

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4433    Accepted Submission(s): 2638


Problem Description
一个正整数,假设从左向右读(称之为正序数)和从右向左读(称之为倒序数)是一样的。这种数就叫回文数。任取一个正整数,假设不是回文数,将该数与他的倒序数相加。若其和不是回文数。则反复上述步骤,一直到获得回文数为止。

比如:68变成154(68+86)。再变成605(154+451),最后变成1111(605+506),而1111是回文数。于是有数学家提出一个猜想:不论開始是什么正整数,在经过有限次正序数和倒序数相加的步骤后,都会得到一个回文数。至今为止还不知道这个猜想是对还是错。如今请你编程序验证之。

 

Input
每行一个正整数。


特别说明:输入的数据保证中间结果小于2^31。

 

Output
相应每一个输入,输出两行。一行是变换的次数。一行是变换的过程。
 

Sample Input
27228 37649
 

Sample Output
3 27228--->109500--->115401--->219912 2 37649--->132322--->355553
 

Author
SmallBeer(CML)
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  1279 1287 1276 1256 1250 
 

Statistic | Submit | Discuss | Note

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;

const  int maxn=1000000;

int n,path[maxn];
char str[maxn],xx[maxn],yy[maxn];

bool isprime(int n)
{
    itoa(n,str,10);
    int len=strlen(str);
    for(int i=0;i<len/2;i++)
    {
        if(str[i]!=str[len-i-1])
            return false;
    }
    return true;
}

int main()
{
    int ok,cnt,temp;
    while(~scanf("%d",&n))
    {
        cnt=0;
        path[++cnt]=n;
        ok=1;
        while(ok)
        {
            if(!isprime(n))
            {
                 int zz=0;
                 itoa(n,xx,10);
                 int len=strlen(xx);
                 for(int i=len-1;i>=0;i--)
                 {
                     yy[zz]=xx[i];
                     zz++;
                 }
                 yy[zz]=‘\0‘;
                 n=n+atoi(yy);
                 path[++cnt]=n;
            }
            else
                ok=0;
        }
        printf("%d\n",cnt-1);
        for(int i=1;i<cnt;i++)
            printf("%d--->",path[i]);
        printf("%d\n",path[cnt]);
    }
    return 0;
}

题2:

UVA10954 ADD ALL(优先队列)

能够说是哈弗曼模型吧

就是给n个数,然后求n个数的和的和最小

就是构造一个数越小优先级越高的队列。每次取前两位,然后求累加和就可以

题目:

Problem F
Add All
Input:
 standard input
Output: standard output

Yup!! The problem name reflects your task; just add a set of numbers. But you may feel yourselves condescended, to write a C/C++ program just to add a set of numbers. Such a problem will simply question your erudition. So, let’s add some flavor of ingenuity to it.

 

Addition operation requires cost now, and the cost is the summation of those two to be added. So, to add 1 and 10, you need a cost of11. If you want to add 12 and 3. There are several ways –

 

1 + 2 = 3, cost = 3

3 + 3 = 6, cost = 6

Total = 9

1 + 3 = 4, cost = 4

2 + 4 = 6, cost = 6

Total = 10

2 + 3 = 5, cost = 5

1 + 5 = 6, cost = 6

Total = 11

 

I hope you have understood already your mission, to add a set of integers so that the cost is minimal.

 

Input

Each test case will start with a positive number, N (2 ≤ N ≤ 5000) followed by N positive integers (all are less than 100000). Input is terminated by a case where the value of N is zero. This case should not be processed.

 

Output

For each case print the minimum total cost of addition in a single line.

 

Sample Input                           Output for Sample Input

3

1 2 3

4

1 2 3 4

0

 

9

19

 


Problem setter: Md. Kamruzzaman, EPS


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;

const int maxn=5000+10;

priority_queue<int,vector<int>,greater<int> >Q;

int a[maxn],n;

int main()
{
    int last,ans;
    while(~scanf("%d",&n),n)
    {
        while(!Q.empty()) Q.pop();
        ans=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&last);
            Q.push(last);
        }
        for(int i=1;i<n;i++)
        {
            int a=Q.top();Q.pop();
            int b=Q.top();Q.pop();
            last=a+b;
            ans+=last;
            Q.push(last);
        }
        printf("%d\n",ans);
    }
    return 0;
}

下一个一个带条件的最小生成树。所以这个题目要想一下。。将毁坏的诚实标记一下。这杨就能够了

题目:

The plan of city rebuild

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


Problem Description
News comes!~City W will be rebuilt with the expectation to become a center city. There are some villages and roads in the city now, however. In order to make the city better, some new villages should be built and some old ones should be destroyed. Then the officers have to make a new plan, now you , as the designer, have the task to judge if the plan is practical, which means there are roads(direct or indirect) between every two villages(of course the village has not be destroyed), if the plan is available, please output the minimum cost, or output"what a pity!".
 

Input
Input contains an integer T in the first line, which means there are T cases, and then T lines follow.
Each case contains three parts. The first part contains two integers l(0<l<100), e1, representing the original number of villages and roads between villages(the range of village is from 0 to l-1), then follows e1 lines, each line contains three integers a, b, c (0<=a, b<l, 0<=c<=1000), a, b indicating the village numbers and c indicating the road cost of village a and village b . The second part first contains an integer n(0<n<100), e2, representing the number of new villages and roads(the range of village is from l to l+n-1), then follows e2 lines, each line contains three integers x, y, z (0<=x, y<l+n, 0<=z<=1000), x, y indicating the village numbers and z indicating the road cost of village x and village y. The third part contains an integer m(0<m<l+n), representing the number of deserted villages, next line comes m integers, p1,p2,…,pm,(0<=p1,p2,…,pm<l+n) indicating the village number. 
Pay attention: if one village is deserted, the roads connected are deserted, too.
 

Output
For each test case, If all villages can connect with each other(direct or indirect), output the minimum cost, or output "what a pity!".
 

Sample Input
2 4 5 0 1 10 0 2 20 2 3 40 1 3 10 1 2 70 1 1 4 1 60 2 2 3 3 3 0 1 20 2 1 40 2 0 70 2 3 0 3 10 1 4 90 2 4 100 0
 

Sample Output
70 160
 

Author
wangjing
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  3081 3082 3087 3086 3079 
 
代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
priority_queue<int,vector<int>,greater<int> >Q;


const int maxn=1000+10;
bool vis[maxn];
int cnt,yy,root[maxn];

struct Edge
{
    int u,v,w;
}edge[maxn*maxn];

bool cmp(Edge a,Edge b)
{
    return a.w<b.w;
}

int findroot(int x)
{
    if(root[x]!=x)
        root[x]=findroot(root[x]);
    return root[x];
}

int kruscal(int n)
{
    for(int i=0;i<maxn;i++)
        root[i]=i;
    int l,r,ans=0;
    int xx=0;
    for(int i=1;i<=cnt;i++)
    {
        int l=edge[i].u;
        int r=edge[i].v;
        int val=edge[i].w;
        if(vis[l]||vis[r])
            continue;
        else
        {
            int fx=findroot(l);
            int fy=findroot(r);
            if(fx==fy)  continue;
            else
            {
                root[fx]=fy;
               // printf("%d %d %d\n",l,r,val);
                ans+=val;
                xx++;
                if(xx==n-1)
                    return ans;
            }
        }
    }
    return -1;
}

int main()
{
    int t,n,m,sum,l,r,mid,newc,newr,old;
    scanf("%d",&t);
    while(t--)
    {
        memset(vis,false,sizeof(vis));
        cnt=0;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%d",&l,&r,&mid);
            edge[++cnt].u=l;
            edge[cnt].v=r;
            edge[cnt].w=mid;
           // printf("%d %d %d\n",l,r,mid);
        }
        scanf("%d%d",&newc,&newr);
        for(int i=1;i<=newr;i++)
        {
            scanf("%d%d%d",&l,&r,&mid);
            edge[++cnt].u=l;
            edge[cnt].v=r;
            edge[cnt].w=mid;
          //  printf("%d %d %d\n",l,r,mid);
        }
        scanf("%d",&old);
        for(int i=1;i<=old;i++)
        {
            scanf("%d",&l);
            vis[l]=true;
        }
        sort(edge+1,edge+1+cnt,cmp);
        int ans=kruscal(n+newc-old);
        if(ans==-1)  printf("what a pity!\n");
        else printf("%d\n",ans);
    }
    return 0;
}

第四个题目 哎 我真是too  young  too simple

我居然看例子那个奇妙的字母是B,然后就以为不变了  

哎  直接枚举A--Z看哪个字母满足条件就可以,

题目:

破译password

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3570    Accepted Submission(s): 1622


Problem Description
有个叫“猪头帮”的国家。採用一种简单的文法加密,他们所用的语言里面仅仅有大写字母,没有其它不论什么字符;如今还知道他们加密的方法是:仅仅用一个大写字母和原文进行异或运算生成密文。

请你帮忙解开。

 

Input
有若干组,每组输入有2行,第一行整数N表示有N个密文,接着一行有N个整数分别表示N个密文。

 

Output
输出仅有大写字母组成的原文。
 

Sample Input
30 17 6 9 8 3 0 1 6 7 4 5 10 11 8 9 14 15 12 13 18 19 16 17 22 23 20 21 26 27 24
 

Sample Output
SDKJABCDEFGHIJKLMNOPQRSTUVWXYZ
 

Author
SmallBeer(CML)
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  1285 1279 1236 1201 1256 
 
z代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
priority_queue<int,vector<int>,greater<int> >Q;


const int maxn=10000+10;

int a[maxn],n;

int main()
{
    char ch;
    int i,j;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for(i=0;i<26;i++)
        {
            ch=i+‘A‘;
            for(j=1;j<=n;j++)
            {
                 if((a[j]^ch)<‘A‘||(a[j]^ch)>‘Z‘)
                     break;
            }
            if(j==n+1)
                break;
        }
        //printf("%c\n",ch);
        for(int i=1;i<n;i++)
            printf("%c",ch^a[i]);
        printf("%c\n",ch^a[i]);
    }
    return 0;
}



codeforces  475 B. Strongly Connected City

这个题目是求全图的联通,由于数据范围非常小。所以直接枚举全部的顶点,然后保搜得到全部的点。

最后看是否所有联通。我sb的把数组开小。导致调了一个中午,哎。郁闷啊  

题目链接:

huangjing

题目:

B. Strongly Connected City
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Imagine a city with n horizontal streets crossing m vertical streets, forming an (n?-?1)?×?(m?-?1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.

技术分享

The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.

Input

The first line of input contains two integers n and m, (2?≤?n,?m?≤?20), denoting the number of horizontal streets and the number of vertical streets.

The second line contains a string of length n, made of characters ‘<‘ and ‘>‘, denoting direction of each horizontal street. If the i-th character is equal to ‘<‘, the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.

The third line contains a string of length m, made of characters ‘^‘ and ‘v‘, denoting direction of each vertical street. If the i-th character is equal to ‘^‘, the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.

Output

If the given pattern meets the mayor‘s criteria, print a single line containing "YES", otherwise print a single line containing "NO".

Sample test(s)
input
3 3
><>
v^v
output
NO
input
4 6
<><>
v^v^v^
output
YES
代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
priority_queue<int,vector<int>,greater<int> >Q;

const int maxn=20+10;

struct Node
{
    int a,b;
}node[maxn*maxn];

bool vis[maxn*maxn][maxn*maxn];
char path[maxn];
int n,m;

void dfs(int xx,int yy)
{
    if(vis[xx][yy]) return;
    else
    {
        vis[xx][yy]=true;
        if(node[yy].a==0&&yy%m!=1)  dfs(xx,yy-1);
        else if(node[yy].a==1&&yy%m!=0)  dfs(xx,yy+1);
        if(node[yy].b==0&&yy>m)  dfs(xx,yy-m);
        else if(node[yy].b==1&&yy<(n*m-m+1))  dfs(xx,yy+m);
    }
}

int main()
{
    int ok;
    while(~scanf("%d%d",&n,&m))
    {
         ok=1;
         scanf("%s",path+1);
         for(int i=1;i<=n;i++)
             for(int j=1;j<=m;j++)
             {
                 if(path[i]==‘<‘)
                    node[m*(i-1)+j].a=0;
                 else
                    node[m*(i-1)+j].a=1;
             }
         scanf("%s",path+1);
         for(int j=1;j<=m;j++)
             for(int i=1;i<=n;i++)
             {
                 if(path[j]==‘^‘)
                    node[m*(i-1)+j].b=0;
                 else
                    node[m*(i-1)+j].b=1;
             }
        for(int i=1;i<=n*m;i++)
        {
            memset(vis,false,sizeof(vis));
            dfs(i,i);
            for(int j=1;j<=n*m;j++)
            {
                if(!vis[i][j])
                {
                    ok=0;
                    break;
                }
            }
            if(!ok)  break;
        }
        if(!ok)  puts("NO");
        else puts("YES");
    }
    return 0;
}


周赛2(星期三之前补题完)

标签:uil   case   sts   center   otto   efi   mis   rmi   1.2   

原文地址:http://www.cnblogs.com/ljbguanli/p/6978349.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!