CodeForces 6A-Triangle(枚举/暴力)

news/2025/2/24 16:38:08

题目描述:

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 2 1 3

7 2 2 4

3 5 9 1

(不是多实例,只是三组测试样例,需分别输入) 

样例输出: 

TRIANGLE

SEGMENT

IMPOSSIBLE  

解题思路: 

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

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

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

直接暴力求解!!!看下面的代码:👇👇👇

AC Code: 

#include<bits/stdc++.h>
using namespace std;
int main() {
	int a[5];
	for(int i=1;i<=4;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=4;i++) {
		for(int j=1;j<=4&&j!=i;j++) {
			for(int k=1;k<=4&&k!=i&&k!=j;k++) {
				if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i]) {
					printf("TRIANGLE\n");
					return 0;
				}
			}
		}
	}
	for(int i=1;i<=4;i++) {
		for(int j=1;j<=4&&j!=i;j++) {
			for(int k=1;k<=4&&k!=i&&k!=j;k++) {
				if(a[i]+a[j]>=a[k]&&a[i]+a[k]>=a[j]&&a[j]+a[k]>=a[i]) {
					printf("SEGMENT\n");
					return 0;
				}
			}
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}


http://www.niftyadmin.cn/n/712824.html

相关文章

纠结的一天 —— 由base64编解码与加号、空格引起

2014年3月14日&#xff0c;星期五&#xff0c; 23点22分 忙碌、焦头烂额、充实而又幸福的一天&#xff01; 写在篇头的话&#xff1a; 许多时候&#xff0c;别人分享的经验&#xff08;成功或失败&#xff09;&#xff0c;个中滋味&#xff0c;听者很难真正体会&#xff0c;直到…

pycharm运行Django项目,提示UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6

确认pycharm编码都是utf-8的情况下&#xff0c;需要修改项目中settings.py DIRS: [ ],默认是空&#xff0c;将路径加入即可解决。 TEMPLATES [{BACKEND: django.template.backends.django.DjangoTemplates,DIRS: [os.path.join(BASE_DIR, templates)],APP_DIRS: True,OPTIONS…

机器学习实战 笔记文章链接

声明 《机器学习实战》读书笔记系列是我对在读此书过程中遇到的各种问题、及解决方法的记录和总结。 另外我修改了部分源代码&#xff0c;并添加了注释&#xff0c;希望能够帮助到大家。 文章列表 《机器学习实战》读书笔记1&#xff1a;NumPy的安装及简单用法 《机器学习实…

android select下拉列表_网页前端开发中常用的html控件(二)button和select【208】

补&#xff1a;想了解input和label请参看我写的文【207】点我进入【207】一、button。是按钮标签&#xff0c;也是按钮标签&#xff0c;它们之间的区别就是button更加强大&#xff0c;它除了可以包含文本之外&#xff0c;还可以包含格式化的文本和图像&#xff0c;这就是它的强…

mysql 结束符报错_数据库之mysql篇(6)—— mysql常用函数函数/自定义函数

常用函数运算函数我相信你都能看懂&#xff0c;所以以上的不再做过多解释然后还有个&#xff0c;前面漏掉的between and:意指10是否在0到20之间&#xff0c;如果是返回1&#xff0c;否则返回0日期函数这个要稍微注意一下参数&#xff0c;第一个是起始日期&#xff0c;interval是…

洛谷P1331-海战(简单的DFS)

题目描述&#xff1a; 在峰会期间&#xff0c;武装部队得处于高度戒备。警察将监视每一条大街&#xff0c;军队将保卫建筑物&#xff0c;领空将布满了F-2003飞机。此外&#xff0c;巡洋船只和舰队将被派去保护海岸线。不幸的是因为种种原因&#xff0c;国防海军部仅有很少的几位…

UITableViewCell的cell重用原理

iOS设备的内存有限&#xff0c;如果用UITableView显示成千上万条数据&#xff0c; 就需要成千上万个UITableViewCell对象的话&#xff0c; 那将会耗尽iOS设备的内存。要解决该问题&#xff0c;需要重用UITableViewCell对象。 &#xff08;苹果一向很注重的应用的性能优化和用户…

Win10 幸免!旧版漏洞 Bug 被发现可致 Win7“崩溃”

安全人员最近发现Windows 7和8.1有一个文件名bug&#xff0c;某些不良文件名使系统锁定或蓝屏死机&#xff0c;恶意网页可以通过使用它们作为图像源来嵌入这些文件名。如果用户使用任何浏览器访问这样的网页&#xff0c;电脑不久就会死机&#xff0c;甚至会可能会直接崩溃。 Wi…