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. nginx 解决问题

  2. 使用R进行数据提取

    使用R进行数据提取 数据提取是数据分析日常工作中遇到最多的需求,本篇文章介绍如何通过R按特定的维度或条件对数据进行提取,完成数据提取需求. 读取并创建数据表 首先第一步是读取数据,并创建名称为loan ...

  3. HTML 排版标记

    <p></p> : 表示一个段落 常用属性 : align : 水平对齐方式  取值 :left  center right 和Word文档一样 : 段落有空行  <br ...

  4. js中的继承和重载

      js中有三种继承方式:一.通过原型(prototype)实现继承 二.借用构造函数式继承,可分为通过call()方法实现继承和通过apply()方法实现继承 仅仅通过原型继承我们可以发现在实例化子 ...

  5. ubuntu关闭防火墙(默认命令)

  6. LOJ#3119 随机立方体

    解:极大值至少为1.我们尝试把最大那个数的影响去掉. 最大那个数所在的一层(指一个三维十字架)都是不可能成为最大值的. 考虑容斥.我们试图求除了最大值以外至少有k个极大值的概率. 我们钦定某k个位置是 ...

  7. css的书写位置+元素分类

    1.css的书写位置 1>行内样式: <span style="color:red;">haha</span> 2>内部样式 在style标签中 ...

  8. Ionic 日期时间插件

    1.插件安装 日期插件 时间插件 备注: 具体 查看 https://github.com/rajeshwarpatlolla/ionic-datepicker    https://github.c ...

  9. #include <filename.h> 和 #include“filename.h” 有什么区别

    对于#include <filename.h> ,编译器从标准库路径开始搜索filename.h,对于#include “filename.h” ,编译器从用户的工作路径开始搜索filen ...

  10. Java虚拟机原理图解-- 1.1、class文件基本组织结构 [转]

    作为Java程序猿,我们知道,我们写好的.java 源代码,最后会被Java编译器编译成后缀为.class的文件,该类型的文件是由字节组成的文件,又叫字节码文件.那么,class字节码文件里面到底是有 ...