第五届河南省程序设计大赛(未完待续.......)

来源:互联网 发布:使命召唤温切斯特数据 编辑:程序博客网 时间:2024/04/26 01:25

奇怪的排序

时间限制:1000 ms  |  内存限制:65535 KB
难度:1
描述

最近,Dr. Kong 新设计一个机器人Bill.这台机器人很聪明,会做许多事情。惟独对自然数的理解与人类不一样,它是从右往左读数.比如,它看到123时,会理解成321.让它比较23与15哪一个大,它说15大。原因是它的大脑会以为是32与51在进行比较.再比如让它比较29与30,它说29大.

给定Bill两个自然数A和B,让它将 [A,B] 区间中的所有数按从小到大排序出来。你会认为它如何排序?

输入
第一行: N表示有多少组测试数据. (2<=N<=5 )
接下来有N行,每一行有两个正整数A B表示待排序元素的区间范围. (1<=A<=B<=200000 B-A<=50)
输出
对于每一行测试数据,输出一行,为所有排好序的元素,元素之间有一个空格.
样例输入
2
8 15   
22 39
样例输出
10 8 9 11 12 13 14 15
30 31 22 32 23 33 24 34 25 35 26 36 27 37 28 38 29 39
来源
第五届河南省程序设计大赛
上传者

ACM_李如兵


#include<stdio.h>#include<algorithm> #include<string.h> #include<math.h> using namespace std;     int t, x;  int n, m;  char q[100000];     struct node  {      int x;      int rx;  }p[10000000];     bool cmp(node a,node b)  {      return a.rx <= b.rx;  }     int main()  {      scanf("%d",&t);      while (t--)      {          scanf("%d%d",&n,&m);          for (int i = n; i <= m; i++)          {              p[i].x = i;              sprintf(q,"%d",i);              int len = strlen(q);              p[i].rx = 0;              for (int j = len - 1; j >= 0; j--)              {                  p[i].rx += pow(10,j) * (int )(q[j] - '0');              }          }          sort(p + n, p + m + 1,cmp);          for (int i = n; i <= m; i++)          {              printf("%d", p[i].x);              if (i != m)                  printf(" ");              else                  printf("\n");          }      }      return 0;  }  

最强DE 战斗力

时间限制:1000 ms  |  内存限制:65535 KB          难度:3
描述

春秋战国时期,赵国地大物博,资源非常丰富,人民安居乐业。但许多国家对它虎视眈眈,准备联合起来对赵国发起一场战争。

显然,面对多个国家的部队去作战,赵国的兵力明显处于劣势。战斗力是决定战争成败的关键因素,一般来说,一支部队的战斗力与部队的兵力成正比。但当把一支部队分成若干个作战队伍时,这个部队的战斗力就会大大的增强。

一支部队的战斗力是可以通过以下两个规则计算出来的:

1.若一支作战队伍的兵力为N,则这支作战队伍的战斗力为N;

2.若将一支部队分为若干个作战队伍,则这支部队的总战斗力为这些作战队伍战斗力的乘积。

比如:一支部队的兵力为5时的战斗力分析如下:

情况

作战安排

总的战斗力

1

1,1,1,1,1(共分为5个作战队伍)

1*1*1*1*1=1

2

1,1,1,2   (共分为4个作战队伍)

1*1*1*2=2

3

1,2,2     (共分为3个作战队伍)

1*2*2=4

4

1,1,3     (共分为3个作战队伍)

1*1*3=3

5

2,3        (共分为2个作战队伍)

2*3=6

6

1,4        (共分为2个作战队伍)

1*4=4

7

5           (共分为1个作战队伍)

5=5

    显然,将部队分为2个作战队伍(一个为2,另一个为3),总的战斗力达到最大!
输入
第一行: N表示有N组测试数据. (2<=N<=5)
接下来有N行,每行有一个整数Ti 代表赵国部队的兵力. (1<=Ti<=1000) i=1,…N
输出
对于每一行测试数据,输出占一行,仅一个整数S,表示作战安排的最大战斗力.
样例输入
254
样例输出
64
来源
第五届河南省程序设计大赛
上传者
ACM_李如兵

试 制 品

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
描述

ZZ大学的Dr.Kong最近发现实验室的很多试制品都已经用完。由于项目经费有限,为了节省,Dr.Kong决定利用实验室现有的试制品来生成所缺的试制品。为此,Dr.Kong连续几天通宵达旦整理出一份研究资料并让研究生Bill去实验并统计能产生多少种所缺的试制品。

Bill从头到尾翻完所有的资料,发现资料上写满了一大堆的化学方程式,上面除了大小写英文字母、数字、加号、等号外,再也没有其他的符号了。其中,每个方程式都是A1+A2+……+Ap=B1+B2+……+Bq的形式, 表示试制品A1,A2,……和Ap反应,生成了试制品B1,B2,……,Bq。其中AiBj都是一种单质或化合物的化学式(长度不超过10个字符),1≤p,q ≤ 20 。每个方程式的总长不超过100个字符。有些试制品的化学式可能在现代社会的化学元素周期表里找不到,这是由于化学反应过程中可能又有物理反应导致的结果。

Bill头疼了,从哪个实验开始呢?你能帮助他吗?

输入
有多组测试数据。
第一行:N表示Dr.Kong写的化学方程式个数(1<=N<=400) 
接下来有N行, 每一行是一个方程式.
再接下来的一行:M表示已有多少种试制品.(1<=M<=500)
接下来有M行,每一行是已有的一种试制品的化学式.
输出
第一行包含一个数T,表示可以产生多少种所缺的试制品.
在接下来的T行中,按ASCII码升序输出产生的试制品的化学式.
样例输入
4H2O+Na=NaOH+H2Cl2+H2=HClFe+O2=Fe3O4NaOH+HCl=H2O+NaCl3H2ONaCl2
样例输出
4H2HClNaClNaOH
来源
第五届河南省程序设计大赛
上传者
ACM_李如兵

遥 控 器

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
描述

Dr.Kong有一台高级电视机,这台电视机可以接受100个频道(从0到99编号)。电视的配套遥控器有13个按钮:

1   2   3   ↑

4   5   6   ↓

7   8   9

—  0

当按"↑"键时,当前频道编号会增加1(如果当前为99频道,则会切换到0频道)。如果按"↓"键,当前频道编号会减小1(如果当前为0频道,则会切换到99频道)。当要切换到0~9频道时,可以直接在遥控器上按相应的键。当要切换到10~99频道时,可以先按"—"键,然后按2个与频道编号相对应的数字键(即先按与频道编号的十位数字相对应的键,然后按与个位数字相对应的键)。

由于遥控器长时间的使用和某些未知原因,遥控器上的某些键已经坏了,不能再起作用了。现在你的任务是,能否告诉Dr.Kong,如何用最少的按键次数来将频道从编号X切换到编号Y
输入
第一行: N表示有N组测试数据. (1<=N<=5)
对每组测试数据有5行,前4行包含遥控器上每个按键的信息。0表示对应的键坏了,1表示对应的键可以使用.第5行包含2个整数,分别是X 和 Y (0 <= X <= 99; 0 <= Y <= 99).
输出
对每组测试数据输出一行,即将频道从编号X切换到编号Y所需要的最小按键次数.如果不可能将频道从编号X 切换到编号Y,则输出-1.
样例输入
20 0 1 1 1 1 1 11 1 11 123 521 1 1 01 1 1 01 0 10 123 52
样例输出
4-1
来源
第五届河南省程序设计大赛
上传者
ACM_李如兵

奇妙的图案

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
描述

最近,Dr. Kong对几何图形发生了浓厚的兴趣。他发现在一个凸多边形里随意加上几个等半径的圆,再将圆涂成不同的颜色,就能构造出一幅美妙的图案。进而,Dr. Kong大发灵感,在此图案的基础上,又加入了几条连接凸多边形的两个不相邻顶点的直线,图形更加奇妙。

           

这时,Dr. Kong遇到了一个问题,他不想让加入的直线相互交叉,也不想让加入的直线穿过凸多边形里的任何一个圆,甚至不能与任何圆相切。

已经知道凸多边形的N个顶点的坐标,也知道了其中M个圆的圆心坐标和半径R。你能帮助Dr. Kong计算出可加上的满足所有条件的最多直线数吗?

输入
第1行: N M R 三个正整数
接下来有N行, 每一行为凸多边形一个坐标TXi TYi (i=1,…,N)
再接下来有M行,每一行为一个圆的圆心坐标PXj PYj (j=1,…,M)
输出
输出有一个整数, 表示可加上的最多直线数。
5≤ N ≤150 0≤ M ≤100 1≤ R ≤100,000 0≤ 所有坐标X,Y≤100,000
样例输入
5 3 16 1010 79 12 00 32 25 68 3
样例输出
1
来源
第五届河南省程序设计大赛
上传者
rihkddd


Metric Matrice

时间限制:1000 ms  |  内存限制:65535 KB
难度:1
描述

Given as input a square distance matrix, where a[i][j] is the distance between point i and point j, determine if the distance matrix is "a  metric" or not.

A distance matrix a[i][j] is a metric if and only if

    1.  a[i][i] = 0

    2, a[i][j]> 0  if i != j

    3.  a[i][j] = a[j][i]

    4.  a[i][j] + a[j][k] >= a[i][k]  i ¹ j ¹ k

输入
The first line of input gives a single integer, 1 ≤ N ≤ 5, the number of test cases. Then follow, for each test case,
* Line 1: One integer, N, the rows and number of columns, 2 <= N <= 30
* Line 2..N+1: N lines, each with N space-separated integers 
(-32000 <=each integer <= 32000).
输出
Output for each test case , a single line with a single digit, which is the lowest digit of the possible facts on this list:
* 0: The matrix is a metric
* 1: The matrix is not a metric, it violates rule 1 above
* 2: The matrix is not a metric, it violates rule 2 above
* 3: The matrix is not a metric, it violates rule 3 above
* 4: The matrix is not a metric, it violates rule 4 above
样例输入
240 1 2 31 0 1 22 1 0 13 2 1 020 32 0
样例输出
03
来源
第五届河南省程序设计大赛
上传者
rihkddd
#include<stdio.h>#include<string.h>int x[35][35];void slove(int n){for(int i=0;i<n;++i) {if(x[i][i]!=0){printf("1\n");return;}}for(int i=0;i<n;++i){for(int j=0;j<n;++j){if(i!=j&&x[i][j]<=0){printf("2\n");return;}}}for(int i=0;i<n;++i){for(int j=0;j<n;++j){if(i!=j&&x[i][j]!=x[j][i]){printf("3\n");return;}}}for(int i=0;i<n;++i){for(int j=0;j<n;++j){for(int k=0;k<n;++k){if(i!=j&&j!=k&&i!=k&&x[i][j]+x[j][k]<x[i][k]){printf("4\n");return ; }}}}printf("0\n");}int main(){int t,n;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=0;i<n;++i){for(int j=0;j<n;++j){scanf("%d",&x[i][j]);}}slove(n);}return 0;} 



Divideing Jewels

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
描述

Mary and Rose own a collection of jewells. They want to split the collection among themselves so that both receive an equal share of the jewels. This would be easy if all the jewels had the same value, because then they could just split the collection in half. But unfortunately, some of the jewels are larger, or more beautiful than others. So, Mary and Rose start by assigning a value, a natural number between one and ten, to each jewel. Now they want to divide the jewels so that each of them gets the same total value. Unfortunately, they realize that it might be impossible to divide the jewels in this way (even if the total value of all jewels is even). For example, if there are one jewel of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the jewels.

输入
Each line in the input file describes one collection of jewels to be divided. The lines contain ten non-negative integers n1 , . . . , n10 , where ni is the number of jewels of value i. The maximum total number of jewells will be 10000. 
The last line of the input file will be "0 0 0 0 0 0 0 0 0 0"; do not process this line. 
输出
For each collection, output "#k:", where k is the number of the test case, and then either "Can be divided." or "Can't be divided.". 
Output a blank line after each test case. 
样例输入
1 0 1 2 0 0 0 0 2 01 0 0 0 1 1 0 0 0 00 0 0 0 0 0 0 0 0 0
样例输出
#1:Can't be divided.#2:Can be divided.
来源
第五届河南省程序设计大赛
上传者
rihkddd

Interesting Punch-Bowl

时间限制:1000 ms  |  内存限制:65535 KB
难度:5
描述

Dr.Kong has taken a side job designing interesting punch-bowl designs. The designs are created as follows:

      * A flat board of size W cm *  H cm is procured        (3 <= W <= 300, 3 <= H <= 300)

      * On every 1 cm x 1 cm square of the board, a 1 cm x 1 cm block is placed.  This block has some integer height B     (1 <= B <= 1,000,000,000)

The blocks are all glued together carefully so that punch will not drain  through them. They are glued so well, in fact, that the corner blocks really don't matter!

Dr.Kong can never figure out, however, just how much punch their bowl designs will hold. Presuming the bowl is freestanding (i.e., no special walls around the bowl), calculate how much juice the bowl can hold.  Some juice bowls, of course, leak out all the juice on the edges and will hold 0.

输入
* Line 1: Two space-separated integers, W and H
* Lines 2..H+1: Line i+1 contains row i of bowl heights: W space-separated integers each of which represents the height B of a square in the bowl. The first integer is the height of column 1, the second integers is the height of column 2, and so on.
There are several test cases and end with the end of the file.
输出
* Line 1: A single integer that is the number of cc's the described bowl will hold.
样例输入
4 5 5 8 7 75 2 1 57 1 7 18 9 6 99 8 9 9
样例输出
12
来源
第五届河南省程序设计大赛
上传者
rihkddd

#include <stdio.h>  #include <string.h>  int a[25],dp[10005],q,maxsum;  int main()  {      int sum,x,step=1,max;      while(1)      {          memset(dp,0,sizeof(dp));          memset(a,0,sizeof(a));          sum=q=maxsum=max=0;          for(int i=0;i<10;i++)          {              scanf("%d",&x);              if(x==0)//如果为0,sum++              {                  sum++;                  continue;              }              if(x%2)//如果x为奇数,maxsum记录所有x的和              a[q++]=i+1,maxsum+=i+1;              else//如果x为偶数              {                  a[q++]=i+1;                  a[q++]=i+1;                  maxsum=maxsum+2*(i+1);              }          }          if(sum==10)//如果有10个0          break;          if(maxsum%2)//如果maxsum不能被2整除  肯定不能均分          {              printf("#%d:Can't be divided.\n",step++);              printf("\n");              continue;          }          for(int i=0;i<q;i++)//动规          for(int j=maxsum/2;j>=a[i];j--)          {              dp[j]=dp[j];              if(dp[j]<dp[j-a[i]]+a[i])              dp[j]=dp[j-a[i]]+a[i];              if(max<dp[j])              max=dp[j];          }          if(max==maxsum/2)//如果max等于maxsum的一半 能均分          printf("#%d:Can be divided.\n",step++);          else          printf("#%d:Can't be divided.\n",step++);          printf("\n");      }      return 0;  } 



蚂蚁感冒

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
描述
长100厘米的细长直杆子上有n只蚂蚁。它们的头有的朝左,有的朝右。 每只蚂蚁都只能沿着杆子向前爬,速度是1厘米/秒。 当两只蚂蚁碰面时,它们会同时掉头往相反的方向爬行。 这些蚂蚁中,有1只蚂蚁感冒了。并且在和其它蚂蚁碰面时,会把感冒传染给碰到的蚂蚁。 请你计算,当所有蚂蚁都爬离杆子时,有多少只蚂蚁患上了感冒。
输入
第一行输入一个整数n (1 < n < 50), 表示蚂蚁的总数。


接着的一行是n个用空格分开的整数 Xi (-100 < Xi < 100), Xi的绝对值,表示蚂蚁离开杆子左边端点的距离。正值表示头朝右,负值表示头朝左,数据中不会出现0值,也不会出现两只蚂蚁占用同一位置。其中,第一个数据代表的蚂蚁感冒了。
输出
要求输出1个整数,表示最后感冒蚂蚁的数目。
样例输入
35 -2 85-10 8 -20 12 25
样例输出
13
来源
第五届蓝桥杯
上传者
TC_杨闯亮

0 0
原创粉丝点击