2529: [Poi2011]Sticks

Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special Judge
Submit: 257  Solved: 133
[Submit][Status][Discuss]

Description

Little
Johnny was given a birthday present by his grandparents. This present
is a box of sticks of various lengths and colours. Johnny wonders if
there are three sticks in the set he has been given that would form a
triangle with different-coloured sides. Let us note that Johnny is
interested in non-degenerate triangles only, i.e., those with positive
area.

给出若干木棍,每根木棍有特定的颜色和长度。问能否找到三条颜色不同的木棍构成一个三角形。
(注意这里所说的三角形面积要严格大于0)

第一行给出一个整数k(3<=k<=50),表示颜色的种数。这k种颜色被标号为1至k。
接下来k行,第i+1描述颜色为i的木棍的信息。
首先一个整数Ni(1<=Ni<=10^6)表示颜色为i的木棍的数量。
接下来Ni个整数,表示这Ni根木棍各自的长度。
所有木棍的长度<=10^9。总木棍数量<=10^6。

你的程序应该仅输出一行
如果有解,输出6个整数,分别表示第一条边的颜色,第一条边的长度,第二条边的颜色,第二条边的长度,第三条边的颜色,第三条边的长度,这六个整数以空格分割。
如果有多组解,随便输出一组即可。
如果无解,输出 NIE

Input

In
the first line of the standard input an integer k(3<=k<=50)is
given, which is the number of different colours of sticks. The colours
themselves are numbered from 1 to k.
The
following klines contain descriptions of the sticks of particular
colours. The line no. i+1holds integers that describe the sticks of
colour , separated by single spaces. The first of these numbers,
Ni(1<=Ni<=10^6) denotes the number of sticks of colour . It is
followed, in the same line, by Niintegers denoting the lengths of the
sticks of colour . All lengths are positive and do not exceed10^9.
Furthermore, the total number of all sticks does not exceed 10^6.0020
In tests worth at least 30% of the points the following holds in addition: the total number of the sticks does not exceed 250.

Output

Your program should print (on the first and only line of the standard output) either:
·        six
integers, separated by single spaces, that describe the construction of
a triangle with different-coloured sides as follows: the colour and the
length of the first stick, the colour and the length of the second
stick, and the colour and the length of the third stick,
·        or the word NIE (Polish for no) if no such triple of sticks exists.
If
there are multiple triples of different-coloured sticks that give rise
to a triangle, your program may pick one such triple arbitrarily.

Sample Input

4
1 42
2 6 9
3 8 4 8
1 12

Sample Output

3 8 4 12 2 9

HINT

Source

 
【题解】
先按照长度排序
从前到后扫描。维护最长的三个颜色不同的木棍即可
证明也比较显然
对于a,b,c
我们证一下如果a,b,c不合题意,那么以c为最大边的其他可能也不会满足题意
分各种情况讨论
发现是对的(唔)
很麻烦,不写了
 
 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b)) inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '')c = ch, ch = getchar();
while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
if(c == '-')x = -x;
} const int MAXN = + ; int k, n; struct Node
{
int num,color;
}node[MAXN]; bool cmp(Node a, Node b)
{
return a.num < b.num;
} int main()
{
read(k);
if(k < )
{
printf("NIE");
return ;
}
for(register int i = ;i <= k;++ i)
{
int tmp;read(tmp);
for(register int j = ;j <= tmp;++ j)
{
node[++n].color = i;
read(node[n].num);
}
}
std::sort(node + , node + + n, cmp);
int p1 = n - ;
while(node[p1].color == node[n].color)-- p1;
int p2 = p1 - ;
while(node[p2].color == node[p1].color || node[p2].color == node[n].color)-- p2;
if(node[p1].num + node[p2].num > node[n].num)
{
printf("%d %d %d %d %d %d", node[n].color,node[n].num,node[p1].color,node[p1].num,node[p2].color,node[p2].num);
return ;
}
for(register int i = n - ;i >= ;-- i)
{
while(node[p1].color == node[i].color)-- p1;
p2 = min(p1 - , p2);
while(node[p2].color == node[p1].color || node[p2].color == node[i].color)-- p2;
if(p2 < || p1 < )break;
if(node[p1].num + node[p2].num > node[i].num)
{
printf("%d %d %d %d %d %d", node[i].color,node[i].num,node[p1].color,node[p1].num,node[p2].color,node[p2].num);
return ;
}
}
printf("NIE");
return ;
}

BZOJ2529

BZOJ2529: [Poi2011]Sticks的更多相关文章

  1. BZOJ2529 [Poi2011]Sticks 【贪心】

    题目链接 BZOJ2529 题解 要组成三角形,当且仅当最长边长度小于另两条边之和 我们就枚举最长边,另两条边当然是越大越好 我们将所有边排序,从小枚举并记录各个颜色的最长边 当枚举到当前边时,找到除 ...

  2. [bzoj2529][Poi2011]Sticks_贪心

    Sticks bzoj-2529 Poi-2011 题目大意:给你n根木棒,每种木棒有长度和颜色,颜色共有k种,求满足条件的3根木棒使得这3根木棒颜色互不相同且可以围成三角形. 注释:$1\le n ...

  3. 【bzoj2529】[Poi2011]Sticks 贪心

    题目描述 给出若干木棍,每根木棍有特定的颜色和长度.问能否找到三条颜色不同的木棍构成一个三角形.(注意这里所说的三角形面积要严格大于0) 输入 第一行给出一个整数k(3<=k<=50),表 ...

  4. POI2011题解

    POI2011题解 2214先咕一会... [BZOJ2212][POI2011]Tree Rotations 线段树合并模板题. #include<cstdio> #include< ...

  5. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  6. LOJ#2170. 「POI2011」木棍 Sticks

    题目链接 题意就是给你一堆线段,然后线段有长度和颜色,让你选三条组成一个三角形,这三条线段颜色不能一样 题解: 做法:贪心 首先按照长度给这些线段排序一遍 然后贪心的去选,对于已经选出来同种颜色的,就 ...

  7. BZOJ_2529_[Poi2011]Sticks_贪心

    BZOJ_2529_[Poi2011]Sticks_贪心 Description Little Johnny was given a birthday present by his grandpare ...

  8. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  9. POJ 2653 Pick-up sticks (线段相交)

    题意:给你n条线段依次放到二维平面上,问最后有哪些没与前面的线段相交,即它是顶上的线段 题解:数据弱,正向纯模拟可过 但是有一个陷阱:如果我们从后面向前枚举,找与前面哪些相交,再删除前面那些相交的线段 ...

随机推荐

  1. escape encodeURI和encodeURIComponent的区别

    escape(与之对应->unescape) escape是对字符串(string)进行编码(而另外两种是对URL),作用是让它们在所有电脑上可读.编码之后的效果是%XX或者%uXXXX这种形式 ...

  2. 19-11-05-Night

    我就是不行. ZJ: 好像是因为郁闷了才咕掉的…… 33 Miemeng 30 00:01:34 40 00:01:46 0 00:01:22 70 00:01:46 不记得当时怎么想的 T1只会暴力 ...

  3. 转:Eclipse中设置编码的方式

    来源:http://blog.csdn.net/jianw2007/article/details/3930915 如果要使插件开发应用能有更好的国际化支持,能够最大程度的支持中文输出,则最好使 Ja ...

  4. HDU 3923 Invoker | 暑训Day1 C题填坑

    暑训第一天,专题为组合数学与概率期望. 最近一个月都没有学习新的知识,上午听聚聚讲课头脑都是一片空白.加上长期没刷题,下午做练习题毫无感觉.到晚上总算理清了蓝书上的一些概念,跟着榜单做题.最后唯独剩下 ...

  5. MacOS 读写 NTFS 即插即用.

    1. 安装osxfusehttps://osxfuse.github.io/ 2. 安装brewhttps://brew.sh/index_zh-cn.html 3. 安装ntfs-3gbrew in ...

  6. Android 开发 防止按键连续点击

    前言 按键防止连续点击是任何一个项目都要考虑的功能.下面我们将介绍几种防止按键连续点击的方法 用工具类实现 /** *@content:按键延时工具类,用于防止按键连点 *@time:2019-5-1 ...

  7. 微信小程序之组件的集合(六)

    这个将是最后一篇关于小程序的记录了,课程接近尾声,最后一个是关于用户的page页面,看看这个页面中有哪些值得学习的地方! 一.page中my开发 这个主要是展示用户喜欢的杂志,以及用户的信息,需要创建 ...

  8. 廖雪峰Java10加密与安全-4加密算法-1对称加密算法

    1.对称加密算法 加密和解密使用同一个密钥,例如WinRAR. WinRAR在对文件进行打包的时候,可以设置一个密码,在解压的时候需要使用同样的密码才能正确的解压. 加密:encrypt(key,me ...

  9. JS创建和存储 cookie的一些方法

    在js中cookie的操作与存储及清除cookie都与时间有关,我们只要把cookie过期时间进行有效的设置我们就可以控制它的存储了,下面我来给大家总结一下js中cookie的一些使用技巧 创建和存储 ...

  10. 深入浅出 Java Concurrency (8): 锁机制 part 3[转]

    接上篇,这篇从Lock.lock/unlock开始.特别说明在没有特殊情况下所有程序.API.文档都是基于JDK 6.0的. public void java.util.concurrent.lock ...