几个题目
题目描述
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
思路:只要弄清楚哪些情况能组成三角形,哪些是退化三角形,哪些不能就行了
#include <stdio.h>
int main()
{
int a[4];
int i,j,temp;
for(i=0; i<4; i++)
scanf("%d",&a[i]);
//先将4跟木棒从小到大排序
for(i=0; i<3; i++)
for(j=i+1; j<4; j++)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
//此处是所有存在能组成三角形的情况
if(a[0]+a[1]>a[3]||a[1]+a[2]>a[3]||a[0]+a[1]>a[2])
printf("TRIANGLE");
//此处是退化三角形情况
else if(a[0]+a[1]==a[2]||a[1]+a[2]==a[3])
printf("SEGMENT");
else
printf("IMPOSSIBLE");
return 0;
}
题目描述
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.
思路:在代码中
#include <stdio.h>
int main()
{
int a,b;//分子b,分母a
scanf("%d%d",&a,&b);
a=a>b?a:b;//将a,b中较大值赋给a
b=7-a;//该女生得分情况总数
a=6;//基本事件总数
//约分
if(b%2==0)
{
b=b/2;
a=6/2;
}
if(a%b==0)
{
a=a/b;
b=1;
}
//
printf("%d/%d",b,a);//概率为得分情况总数除以基本事件总数
return 0;
}
题目描述
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
思路:输入字符数字,然后将字符数字从小到大排序(这种情况该数重排就是最小的),再考虑前导为0的情况
代码:
#include <stdio.h>
#include <string.h>
int main()
{
char a[10],b[10],temp;
scanf("%s%s",a,b);
int i;
//排序,小的字符往前排
for(i=0;i<strlen(a);i++)
for(int j=i+1;j<strlen(a);j++)
if(a[i]>=a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
//如果第一个数为0
if(a[0]=='0')
{
for(i=0;i<strlen(a);i++)
{
if(a[i]!='0')//找到第一个不为0的数,让它与第一个为0的数交换
{
temp=a[0];
a[0]=a[i];
a[i]=temp;
break;
}
}
}
if(strcmp(a,b)==0)//比较重排后的数和目标数
printf("OK");
else
printf("WRONG_ANSWER");
return 0;
}
题目描述
由数字00组成的方阵中,有一任意形状闭合圈,闭合圈由数字11构成,围圈时只走上下左右44个方向。现要求把闭合圈内的所有空间都填写成22.例如:6 \times 66×6的方阵(n=6n=6),涂色前和涂色后的方阵如下:
0 0 0 0 0 0
0 0 1 1 1 1
0 1 1 0 0 1
1 1 0 0 0 1
1 0 0 0 0 1
1 1 1 1 1 1
0 0 0 0 0 0
0 0 1 1 1 1
0 1 1 2 2 1
1 1 2 2 2 1
1 2 2 2 2 1
1 1 1 1 1 1
输入格式
每组测试数据第一行一个整数n(1 \le n \le 30)n(1≤n≤30)
接下来nn行,由00和11组成的n \times nn×n的方阵。
方阵内只有一个闭合圈,圈内至少有一个00。
//感谢黄小U饮品指出本题数据和数据格式不一样. 已修改(输入格式)
输出格式
已经填好数字22的完整方阵。
输入输出样例
输入 #1复制
6 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 1 1 1 1 1 1 1
输出 #1复制
0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 2 2 1 1 1 2 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1
说明/提示
1 \le n \le 301≤n≤30
思路:1.先将所有0变为2
2.在n*n矩阵外加一圈2
3.从第一个2也就是(0,0)开始搜索
4.此时搜到的都是边界外的2,将这些2变为0
代码如下:
#include <stdio.h>
int df[4][4]= {{1,0},{0,1},{-1,0},{0,-1}};
int n;
int mark[200][200];
int v[200][200];
void dfs(int i,int j)
{
if(v[i][j])//搜到边界就停止
return;
v[i][j]=1;
for(int a=0; a<4; a++)
{
int c=i+df[a][0];
int d=j+df[a][1];
if(c>=0&&c<=n+1&&d>=0&&d<=n+1&&mark[c][d]==2&&v[c][d]==0)//可以搜的情况
{
mark[c][d]=0;//将边界外的2变为0
dfs(c,d);
}
}
}
int main()
{
scanf("%d",&n);
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
{
scanf("%d",&mark[i][j]);
if(mark[i][j]==0)
mark[i][j]=2;
}
for(int i=0; i<=n+1; i++)//外圈加一圈2
{
mark[0][i]=2;
mark[i][0]=2;
mark[n+1][i]=2;
mark[i][n+1]=2;
}
dfs(0,0);
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
printf("%d ",mark[i][j]);
}
printf("\n");
}
return 0;
}
发现搜索题组已经关闭,我才写了几个啊