http://codeforces.com/gym/101097/attachments

题意:现在有k种颜色的木棍,每种颜色有ni根木棍,每根木棍有一个长度,问是否有三根木棍可以组成三角形,并且这三根木棍的颜色都不相同。

思路:忘了并不能直接枚举第i根,然后找i-1和i-2根,因为还有很多情况没考虑到。

可以用三个变量,分别存储当前最大的三种颜色的最大值,然后根据新进来的颜色进行判定,进行更新。

 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define N 5000010
#define INF 0x3f3f3f3f
struct node {
int id; LL val;
bool operator < (const node &rhs) const {
if(val != rhs.val) return val < rhs.val;
return id < rhs.id;
}
} ;
vector<LL> vec;
vector<node> p;
node a, b, c; int main() {
freopen("sticks.in", "r", stdin);
freopen("sticks.out", "w", stdout);
int k; scanf("%d", &k);
int cnt = ;
for(int i = ; i <= k; i++) {
int n; scanf("%d", &n);
vec.clear();
for(int j = ; j <= n; j++) {
LL x; scanf("%lld", &x);
vec.push_back(x);
}
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for(int j = ; j < vec.size(); j++) p.push_back( (node) { i, vec[j] } );
}
sort(p.begin(), p.end());
bool flag = ;
// a = p[1]; b = p[0]; c.id = 0, c.val = 0;
for(int i = ; i < p.size() && !flag; i++) {
if(a.id == p[i].id) {
if(p[i].val < b.val + c.val) printf("%d %lld %d %lld %d %lld\n", p[i].id, p[i].val, b.id, b.val, c.id, c.val), flag = ;
a = p[i];
} else if(b.id == p[i].id) {
if(p[i].val < a.val + c.val) printf("%d %lld %d %lld %d %lld\n", p[i].id, p[i].val, a.id, a.val, c.id, c.val), flag = ;
b = a; a = p[i];
} else {
if(p[i].val < a.val + b.val) printf("%d %lld %d %lld %d %lld\n", p[i].id, p[i].val, a.id, a.val, b.id, b.val), flag = ;
c = b; b = a; a = p[i];
}
}
if(!flag) puts("NIE");
return ;
}

Codeforces Gym101097I:Sticks (思维)的更多相关文章

  1. CodeForces 604C 【思维水题】`

    题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次 ...

  2. Minimum Integer CodeForces - 1101A (思维+公式)

    You are given qq queries in the following form: Given three integers lili, riri and didi, find minim ...

  3. Codeforces 1038D - Slime - [思维题][DP]

    题目链接:http://codeforces.com/problemset/problem/1038/D 题意: 给出 $n$ 个史莱姆,每个史莱姆有一个价值 $a[i]$,一个史莱姆可以吃掉相邻的史 ...

  4. AND Graph CodeForces - 987F(思维二进制dfs)

    题意:给出n(0≤n≤22)和m,和m个数ai,1 ≤ m ≤ 2n ,0≤ai<2n ,把ai & aj == 0 的连边,求最后有几个连通块 解析:一个一个去找肯定爆,那么就要转换一 ...

  5. CodeForces - 631C ——(思维题)

    Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...

  6. codeforces 571A--Lengthening Sticks(组合+容斥)

    A. Lengthening Sticks time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. Almost Acyclic Graph CodeForces - 915D (思维+拓扑排序判环)

    Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megaby ...

  8. Diagonal Walking v.2 CodeForces - 1036B (思维,贪心)

    Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point ( ...

  9. CodeForces - 1102A(思维题)

    https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...

随机推荐

  1. hibernate关于多对多注解配置

    Game实体类配置关系 @Entity @Table(name = "game") public class Game { @Id @GeneratedValue private ...

  2. U3D游戏开发商思考

    代码驱动带来的技术题 游戏碎片化.U3D 引擎有个非常有力的特色,就是实时编译执行.这意味着不管在不论什么时候,仅仅要按下执行图标,当前的场景就会进入可执行状态. 这导致了游戏在开发的过程中常常陷入一 ...

  3. Servlet 3.1实践

    Servlet 3.1 新特性详解 参考: IBM developerworks: Servlet 3.0 新特性详解 开涛的博客: Servlet3.1规范(最终版) 关键特性 Asynchroni ...

  4. SICP 1.9-1.10

    1.9 2^102^162^16 2n2^(n)2的(n-1)层次方(每一层都是2次方) 比如 h(4) = 2^(2^(2^2)) = 2^16

  5. 对复杂字典Dictionary<T1,T2>排序问题

    原文:对复杂字典Dictionary<T1,T2>排序问题 //VoltageCount类(电压值对应的数量):    public class VoltageCount    {     ...

  6. Codejock.Xtreme.Toolkit.Pro.v15.3.1 下载 与 VS2015补丁使用方法

    Codejock.Xtreme.Toolkit.Pro.v15.3.1 下载 与 VS2015补丁使用方法 打算放在CSDN进行下载的,上传完成后发现资源分设置的1分,本打算赚点下载分的.在页面上没有 ...

  7. MugLife静态照片变3D动画算法研究

    原文:MugLife静态照片变3D动画算法研究 MugLife app是一款可以将静态照片变成3D动画的手机应用,如下效果图所示: 大家可以看到,这个静态图具有了类3D的动画特效,是不是很好玩? 这种 ...

  8. java中==和equels的区别

    起初接触java的时候这个问题还是比较迷茫的,最近上班之余刷博客的时候看了一些大神写的文章,自己也来总结一下,直接贴代码: package string; public class demo1 { p ...

  9. 零元学Expression Blend 4 - Chapter 40 Flash做的到的Blend也可以!轻松制作拥有动画的MenuBar!(上)

    原文:零元学Expression Blend 4 - Chapter 40 Flash做的到的Blend也可以!轻松制作拥有动画的MenuBar!(上) 一直以来都有人拿Flash的动画问我Blend ...

  10. Elevate Web Builder for Web Developers(类似于unigui的东西)

    推荐一款pascal 语言的web 开发工具 这几天仔细研究了一款使用Pascal 语言开发web 的工具 具体介绍可以参照这里. 先上几张他开发的页面照.