2022.1.16(测试题解)

总结:今天测试ac了3个题目,两个都用了快排,嘿嘿

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.

题意翻译

题目描述

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

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

输入格式

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

输出格式

如果它们中存在 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

思路

1、dfs

2、用快排把4个数字从小到大排序

3、判断前两个数字之和,用flag标记(初始化为0)

4、大于第三个就是三角形 flag=1;等于第3个并且flag=0(即不满足第一种)就是退化三角形flag=2;都不满足flag还等于0;

5、判断flag,输出TRIANGLE或SEGMENT 或IMPOSSIBLE

代码实现 

#include <stdio.h>
int a[100],b[100],flag=0,step;
void fun(int left,int right)
{
	int i,j,t,temp;
	if(left>right)
		return;
	temp=a[left];
	i=left;j=right;
	while(i!=j)
	{
		while(a[j]>=temp&&i<j)
			j--;
		while(a[i]<=temp&&i<j)
			i++;
		if(i<j)
		{
			t=a[i];
			a[i]=a[j];
			a[j]=t;
		}
	}
	a[left]=a[i];
	a[i]=temp;
	fun(left,i-1);
	fun(i+1,right);
} 
void dfs(int x ,int y){
    if (y == 4){
        if(b[1]+b[2]>b[3])
            flag=1;
        if(b[1]+b[2]==b[3]&&!flag)
            flag=2;
        return;
    }
    for (int i = x; i <= 4 ; ++i) {
        b[x] = a[i];
        dfs(i+1,y+1);
    }
    return;
}
int main(){
    for (int i = 1; i <= 4; ++i) {
        scanf("%d",&a[i]);
    }
    fun(1,4);//排序
    //for(int i=0;i<4;i++)
    //printf("%d",a[i]);
    dfs(1,1);
    if(flag==0) printf("IMPOSSIBLE");
    if(flag==2) printf("SEGMENT");
    if(flag==1) printf("TRIANGLE");
    return 0;

}

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.

思路

就是6种情况,算一下就好了,直接看代码吧!!

代码实现 

#include <stdio.h>
int max(int x,int y)
{
	if(x>y)
		return x;
	else
		return y;
}
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    a=max(a,b);
    if(a==1)
        printf("1/1");
    else if(a==2)
        printf("5/6");
    else if(a==3)
        printf("2/3");
    else if(a==4)
        printf("1/2");
    else if(a==5)
        printf("1/3");
    else if(a==6)
        printf("1/6");
    return 0;
}

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.

题意翻译

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

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

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

输入格式

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

输出格式

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

Translated by LiM_817

输入输出样例

输入 #1复制

3310
1033

输出 #1复制

OK

输入 #2复制

4
5

输出 #2复制

WRONG_ANSWER

思路

1、把数字n的每一位都存在数组a里

2、把数组进行从小到大的排列

3、如果第一个数a【0】是0的话,就找到后面第一个不是零的数,和a【0】进行交换

4、for(int i=2;i<=t;i++)
    {
        k=k*10+a[i];
    }

像这样把他算出来

5、把算出的k和输入的m进行比较

6、如果相等就输出ok;否则就是WRONG_ANSWER

代码实现 

#include<stdio.h>
int n,m,a[100],k;
void fun(int left,int right)
{
	int i,j,t,temp;
	if(left>right)
		return;
	temp=a[left];
	i=left;j=right;
	while(i!=j)
	{
		while(a[j]>=temp&&i<j)
			j--;
		while(a[i]<=temp&&i<j)
			i++;
		if(i<j)
		{
			t=a[i];
			a[i]=a[j];
			a[j]=t;
		}
	}
	a[left]=a[i];
	a[i]=temp;
	fun(left,i-1);
	fun(i+1,right);
} 
int main()
{
	scanf("%d%d",&n,&m);
	int temp=n,t=0;
	while(n)
	{
		a[++t]=n%10;
		n=n/10;
	}
	fun(1,t);
	//for(int i=1;i<=t;i++)
	//printf("%d\n",a[i]);
	if(a[1]==0)
	{
		for(int i=2;i<=t;i++)
		{
			if(a[i]!=0)
			{
				int temp=a[i];
				a[i]=a[1];
				a[1]=temp;
				break;
			}
		}
	}
	k=a[1];
	for(int i=2;i<=t;i++)
	{
		k=k*10+a[i];
	}
	//printf("%d",k);
	if(k==m)
		printf("OK");
	else
		printf("WRONG_ANSWER");
} 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值