周赛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

杭电ACM集训队训练赛(VII)

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

HDU 2nd “Vegetable-Birds Cup” Programming
Open Contest

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看哪个字母满足条件即可,

题目:

破译密码

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

杭电ACM集训队训练赛(VII)

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;
}
时间: 2024-10-11 23:04:43

周赛2(星期三之前补题完)的相关文章

2020-3-14 acm训练联盟周赛Preliminaries for Benelux Algorithm Programming Contest 2019 解题报告+补题报告

2020-3-15比赛解题报告+2020-3-8—2020-3-15的补题报告 2020-3-15比赛题解 训练联盟周赛Preliminaries for Benelux Algorithm Programming Contest 2019  A建筑(模拟) 耗时:3ms 244KB 建筑 你哥哥在最近的建筑问题突破大会上获得了一个奖项 并获得了千载难逢的重新设计城市中心的机会 他最喜欢的城市奈梅根.由于城市布局中最引人注目的部分是天际线, 你的兄弟已经开始为他想要北方和东方的天际线画一些想法

4.30-5.1cf补题

//yy:拒绝转载!!! 悄悄告诉你,做题累了,去打两把斗地主就能恢复了喔~~~ //yy:可是我不会斗地主吖("'▽'") ~~~那就听两遍小苹果嘛~~~ 五一假期除了花时间建模,就抽空把最近没做的CF题补了点..毕竟明天开始又要继续上好多课呐...Yes, I can!(? •_•)?……(I can Huá shuǐ~~) codeforces 803 A. Maximal Binary Matrix   [简单构造] 题意:n行和n列填充零矩阵. 您要将k个1放在其中,使得得到

[2015hdu多校联赛补题]hdu5348 MZL&#39;s endless loop

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5348 题意:给你一个无向图,要你将无向图的边变成有向边,使得得到的图,出度和入度差的绝对值小于等于1,如果无解输出-1 解:考虑奇数度的点一定会成对出现(因为所有度数和肯定是偶数个->因为一条边产生两度~),那么我们可以将奇数度的点两两一连消除掉(两奇数度点的出度入读差的绝对值都为1, 路径上的点的差绝对值为0) 然后偶数度的点可以成环,那么可以搜出所有的环 1 /* 2 * Problem: 3

[2015hdu多校联赛补题]hdu5371 Hotaru&#39;s problem

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5371 题意:把一个数字串A翻过来(abc翻过来为cba)的操作为-A,我们称A-AA这样的串为N-sequence,现在给你一个数字串,问你这个串中最长的N-sequence子串长度 解:可以想到A-A是一个回文串,-AA也是一个回文串,那么首先Manacher跑一遍求出所有回文子串 可以想到任意两个互相覆盖的回文子串都可以表示成N-sequence 然后有三种搞法: 1.时间复杂度O(N*logN

补题 留空

这两道题虽然不是很难,但是目前还不会,在这留个地,省赛之后多刷点这种类型的题,再补上. 1. http://acm.hdu.edu.cn/showproblem.php?pid=3306 矩阵快速幂的题,相加平方和. 2.http://acm.hdu.edu.cn/showproblem.php?pid=3308 线段树 补题 留空,码迷,mamicode.com

hdu5017:补题系列之西安网络赛1011

补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为min(a,b,c) 所以我们需要把原方程化为标准型. 这时候线代就排上用场了,注意到原方程是一个二次型. 化为标准型 1/(k1)*x^2+1/(k2)*y^2+1/(k3)*z^2=1 后  min(k1,k2,k3)即为答案 而这里的1/k1,1/k2,1/k3 就是二次型矩阵的特征值 如何求特

[补题]ACM-ICPC 2017 Asia Xi&#39;an

G: 题意:查询[l,r]子区间异或的和 题解: 按位考虑,每一位统计奇数区间出现的次数算价值即可,线段树区间合并 #include <bits/stdc++.h> #define ll long long const ll mod=1e9+7; const int MAXN=1e5+10; using namespace std; typedef struct node{ int len,llen,rlen,sum;ll ans; }node; node d[21][MAXN*3+10005

2018 HDU多校第三场赛后补题

2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube 题意: 在画布上画一个三维立方体. 题解: 模拟即可. 代码: #include <bits/stdc++.h> using namespace std; int a, b, c, R, C; char g[505][505]; int main () { int T; cin >>

(补题 杭电 2046)骨牌铺方格

骨牌铺方格 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 68313 Accepted Submission(s): 32884 Problem Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图: Input 输入数据由