ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

寒假第一周测试题

2022-01-16 18:30:56  阅读:169  来源: 互联网

标签:输出 第一周 int 18 测试题 寒假 复制 Bob 输入


1、CF6A Triangle

题目描述

Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.

The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.

输入格式

The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.

输出格式

Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.

题意翻译

题目描述

给定 4 根木棍的长度,如果它们中存在 3 根木棍可以组成三角形,输出 TRIANGLE ;如果它们无法组成三角形,但是它们中存在 3 根木棍可以组成退化的三角形(任意两边之和大于等于第三边,但是不是三角形),输出 SEGMENT ;否则,输出 IMPOSSIBLE 。

注意: 木棍不能折断,也不能只用一部分长度。

输入格式

一行 4 个整数,4 根木棍的长度。

输出格式

如果它们中存在 33 根木棍可以组成三角形,输出 TRIANGLE ;如果它们无法组成三角形,但是它们中存在3根木棍可以组成退化的三角形,输出 SEGMENT ;否则,输出 IMPOSSIBLE

By @PC_DOS

输入输出样例

输入 #1复制

4 2 1 3

输出 #1复制

TRIANGLE

输入 #2复制

7 2 2 4

输出 #2复制

SEGMENT

输入 #3复制

3 5 9 1

输出 #3复制

IMPOSSIBLE

 题解:直接深搜四根木棍能选出的每一种三条边的组合(即四个数中选出三个数的组合),然后再判断每一组是否能组成三角形或者退化三角形。

#include <stdio.h>
int a[4],b[3],book[4];
int flag1,flag2;
void dfs(int step)
{ if(step==3)
  {if(b[0]+b[1]>b[2]&&b[0]+b[2]>b[1]&&b[1]+b[2]>b[0])//能组成三角形 
    flag1=1;
   else if(b[0]+b[1]>=b[2]&&b[0]+b[2]>=b[1]&&b[1]+b[2]>=b[0])// 退化三角形 
    flag2=1; 
   return;
  }
  for(int i=0;i<4;i++)
   if(!book[i])
   {book[i]=1;
    b[step]=a[i];
	dfs(step+1);
	book[i]=0; 
   }
  
}
main()
{ for(int i=0;i<4;i++)
  scanf("%d",&a[i]);
  dfs(0);//从下标为0开始
  if(flag1==1)
   printf("TRIANGLE\n");
  else if(flag2==1)
   printf("SEGMENT\n");
  else
   printf("IMPOSSIBLE\n"); 
} 

2、CF9A Die Roll 

题目描述

Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.

But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.

Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.

It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.

输入格式

The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.

输出格式

Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».

题意翻译

小Y,小W和小D进行扔骰子(六面)游戏,谁投出的点数最大算谁胜利,现在已知小Y和小W的得分,请你帮小D求出她获胜的概率

注意:

1.以"分子/分母"输出,特别的,若不可能获胜输出"0/1",100%获胜输出"1/1"

2.小Y和小W非常绅士,如果小D的得分和他们一样,他们也会算作小D获胜 Translated by @稀神探女

输入输出样例

输入 #1复制

4 2

输出 #1复制

1/2

说明/提示

Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.

 题解:本题只需找出比小Y和小W两者中较大的那个点数大于或等于的点数占比即可,如小Y 4点,小W 3点,则小D 4、5、6点即可,因为骰子总共点数为6点,所以她的点数占比为1/2,而当小Y和小W两者的点数都是1点(即两则中最大点数为1点)那么小D必赢;而因为小D大于或等于小Y和小W的就算赢,所以没有不可能获胜的情况(即没可能输出0/1),本题再将占比约分即可。  

#include <stdio.h>
main()
{int a,b,fz,fm=6;
 scanf("%d%d",&a,&b);
 fz=6-(a>b?a:b)+1;
 if(fz==6)//必胜情况 
  printf("1/1");
 else
 {int i;
   for(i=5;i>1;i--)
    if(fz%i==0&&fm%i==0)
     break;
   fz/=i;//约分 
   fm/=i;
   printf("%d/%d",fz,fm);  
 }
}

3、CF12B Correct Solution? 

题目描述

One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number nn to Bob and said:

—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.

—No problem! — said Bob and immediately gave her an answer.

Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.

输入格式

The first line contains one integer nn ( 0<=n<=10^{9}0<=n<=109 ) without leading zeroes. The second lines contains one integer mm ( 0<=m<=10^{9}0<=m<=109 ) — Bob's answer, possibly with leading zeroes.

输出格式

Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.

题意翻译

题目描述(舍弃各种乱七八糟的故事)

给定一个数N,要求把N的各个数位打乱,要求组成一个可能的,最小的数(最小数有可能含有前导0)。现在已经有一个“最小数”,请你判断这个“最小数”是不是最小数。

第一行输入n不含前导0。
第二行输入的假定的最小数可能含有前导0。 题目要求排序后的最小数不含前导0。

输入格式

两行。 第一行是给定的数N。 第二行是假定的N重组的“最小数”。

输出格式

一行。 如果输入的最小数就是N重组的最小数,输出“OK”。 否则输出“WRONG_ANSWER”。

Translated by LiM_817

输入输出样例

输入 #1复制

3310
1033

输出 #1复制

OK

输入 #2复制

4
5

输出 #2复制

WRONG_ANSWER

 题解:本题可以将输入的两个数按字符串输入,然后通过深搜进行重新组合找出没有前导0的最小值,最后判断最小值是否与预测值相等即可。
从0开始深搜,找出输入的数能重新组合的所有形式,当步数等于数字的长度时就表示一种情况完成,然后判断该种情况是否为无前导0的数(即数组重新组合排在第一个的不能是0),若为无前导0的数则将它与最小值进行比较并将更小的保存下来,这样就能找到无前导0的最小的数。

#include <stdio.h>
#include <string.h>
char a[20],b[20],t[20],min[20]="9999999999999";
int book[20];
void dfs(int step)
{if(step==strlen(a))
 { if(t[0]=='0'&&strlen(a)!=1)//前导0的情况,strlen(a)!=1可能有一个数字0的情况 
     return;
   if(strcmp(t,min)<0) strcpy(min,t);
   return;
 }
 for(int i=0;i<strlen(a);i++)
 {if(!book[i])
  {book[i]=1;
   t[step]=a[i];
   dfs(step+1);
   book[i]=0;
  }
 }
}
main()
{scanf("%s",a);
 scanf("%s",b);
 dfs(0);
 if(strcmp(min,b)==0)//没有前导0的最小值与预测结果相同
  printf("OK\n");
 else
  printf("WRONG_ANSWER\n");
}

 4、CF30B Codeforces World Finals

 

题目描述

The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that after it the brightest minds will become his subordinates, and the toughest part of conquering the world will be completed.

The final round of the Codeforces World Finals 20YY is scheduled for DDDD . MMMM . YYYY , where DDDD is the day of the round, MMMM is the month and YYYY are the last two digits of the year. Bob is lucky to be the first finalist form Berland. But there is one problem: according to the rules of the competition, all participants must be at least 18 years old at the moment of the finals. Bob was born on BDBD . BMBM . BYBY . This date is recorded in his passport, the copy of which he has already mailed to the organizers. But Bob learned that in different countries the way, in which the dates are written, differs. For example, in the US the month is written first, then the day and finally the year. Bob wonders if it is possible to rearrange the numbers in his date of birth so that he will be at least 18 years old on the day DDDD . MMMM . YYYY . He can always tell that in his motherland dates are written differently. Help him.

According to another strange rule, eligible participant must be born in the same century as the date of the finals. If the day of the finals is participant's 18-th birthday, he is allowed to participate.

As we are considering only the years from 20012001 to 20992099 for the year of the finals, use the following rule: the year is leap if it's number is divisible by four.

输入格式

The first line contains the date DDDD . MMMM . YYYY , the second line contains the date BDBD . BMBM . BYBY . It is guaranteed that both dates are correct, and YYYY and BYBY are always in [01;99][01;99] .

It could be that by passport Bob was born after the finals. In this case, he can still change the order of numbers in date.

输出格式

If it is possible to rearrange the numbers in the date of birth so that Bob will be at least 18 years old on the DDDD . MMMM . YYYY , output YES. In the other case, output NO.

Each number contains exactly two digits and stands for day, month or year in a date. Note that it is permitted to rearrange only numbers, not digits.

题意翻译

题意描述

关于 Codeforces 的网站 king Copa 经常被报道,使得它在要使用网站进行训练和比赛的人之间迅速流行开来。最近, Copa 明白,要征服世界,他需要组织世界 Codeforces 锦标赛。他希望在这次比赛之后之后,最聪明的人将成为被挑选出来成为他的下属,然后征服世界最艰难的部分将会完成。

Codeforces 世界总决赛的最后一轮定于 YYYY 年 MMMM 月 DDDD 日举行,其中 DDDD 是当天的日期, MMMM 是当月的月份, YYYY 是当年的年份的最后两位。Bob 很幸运地能成为来自 Berland 的一名决赛选手。但有一个问题:根据比赛规则,所有参赛者在决赛时必须年满 1818 岁。 Bob 出生于 BYBY 年, BMBM 月,BDBD 日。这个日期记录在他的护照上,他的护照复印件已经寄给了组织者。但是 Bob 了解到,在不同的国家,日期的书写方式是不同的。例如,在美国,先写月份,然后写日期,最后写年份。

鲍勃想知道是否有可能重新排列他出生日期的数字,以便他在 YYYY 年, MMMM 月, DDDD 日那天至少 1818 岁。他看出,在他的祖国,日期写的顺序不一样。请帮帮他。 根据另一个奇怪的规则,合格的参赛者必须与决赛日期出生在同一个世纪。如果决赛当天刚好是参赛者的 1818 岁生日,则他可以参加。

因为我们只考虑从 20012001 年到 20992099 年的决赛年份,所以使用以下规则:如果年份的数字可以被 44 整除,那么年份就是闰年。

输入格式:

第一行包括三个数字 DD,MM,YYDD,MM,YY ,第二行包括三个数字 BD,BM,BYBD,BM,BY ,数据保证两个日期的正确性,并且 BYBY 和 YYYY 保证在 [ 01 ,99 ][01,99] 中。

输出格式:

如果可能通过重新排列出生日期的顺序,让 Bob 在比赛当天至少 1818 岁,则输出 YES 。如果不能,则输出 NO。

输入输出样例

输入 #1复制

01.01.98
01.01.80

输出 #1复制

YES

输入 #2复制

20.10.20
10.02.30

输出 #2复制

NO

输入 #3复制

28.02.74
28.02.64

输出 #3复制

NO

 题解:本题即将年月日三个数通过深搜把它的顺序重新组合,判断是否能找到让参赛选手最能年龄能大于18岁。不过在组合时他的日数和月份都应满足日常生活的常识(即月份最多12个月,每月不同天数28、29、30、31,不应大于它们或者为负数),判断是否年满18还有三种情况即1、两者年数相隔大于18,2、两者年数相隔等于18但出生月份小于比赛月份,3、年数和月份都想等那么出生的天数就要小于等于比赛天数。

#include <stdio.h>
int a[3],b[3],t[3],book[3],flag=0;
void dfs(int step)
{ if(step==3)
  { int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    if((2000+t[2])%4==0)
     month[2]++;
    if(t[0]>month[t[1]]||t[1]>12)//月数或者每月天数大于正常情况 
     return;
    if((a[2]-t[2]==18&&a[1]>t[1])||a[2]-t[2]>=18&&a[1]==t[1]&&a[0]>=t[0]||a[2]-t[2]>18)
	 flag=1;
	return;  
  }
  for(int i=0;i<3;i++)
  if(!book[i])
  {book[i]=1;
   t[step]=b[i];
   dfs(step+1);
   book[i]=0;
  }
}
main()
{scanf("%d.%d.%d",&a[0],&a[1],&a[2]);
 scanf("%d.%d.%d",&b[0],&b[1],&b[2]);
 dfs(0);
 if(flag)
  printf("YES");
 else
  printf("NO"); 
} 

 

标签:输出,第一周,int,18,测试题,寒假,复制,Bob,输入
来源: https://blog.csdn.net/qq_63701383/article/details/122525876

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有