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. CentOS6.8环境安装oracle 11G

    本节所讲内容: oracle11g基础环境配置 数据库的三种安装方式(图形.静默.克隆) http://db-engines.com REDHAT6.5安装oracle11.2.4 ORACLE11G ...

  2. Binding的详细说明

    <DataGridTextColumn Width="*" Header=" 组合规则名称 " Binding="{Binding ComRul ...

  3. 通通WPF随笔(3)——艺术二维码素材生成器

    原文:通通WPF随笔(3)--艺术二维码素材生成器 最近公司让我开发一个条形码的生成控件,花了半天时间搞定觉得不过瘾,什么年代了该用二维码了吧.于是wiki了一下二维码的资料. 比较常见的就是QR码( ...

  4. 【全面解禁!真正的Expression Blend实战开发技巧】第二章 你好,UI设计师

    原文:[全面解禁!真正的Expression Blend实战开发技巧]第二章 你好,UI设计师 你好,UI设计师 曾几何时我从没想过要与艺术家打交道,但是Silverlight改变了这一切.UI设计师 ...

  5. Linux下基于Bluez

    硬件:Moto H670 蓝牙耳机 (CSR chip)/ Broadcom v2.0 adapter软件:bluez-4.26 / bluez-gnome-1.8 / linux kernel 2. ...

  6. ReportViewer,RDLC 报表开发之个性化样式

    原文:ReportViewer,RDLC 报表开发之个性化样式 报表开发中,客户对样式提出了要求: 1.工具栏上显示每页条数 2.只导出Excel,不需要下拉菜单. 3.报表上显示的图表,分页时,每页 ...

  7. VS2015设置VS2017的“快速操作”快捷键Alt+Enter

    选项 -  环境 - 键盘 - 视图.快速操作和重构 添加“Alt+Enter (文本编辑器)”

  8. 声谱预测网络(Tacotron2)

    整个特征预测网络是一个带有注意力机制(attention)的seq2seq网络. 编码器-解码器(Encoder-Decoder)结构 在原始的编码器-解码器结构中,编码器(encoder)输入一个序 ...

  9. SVN更新报错问题(Please execute the 'Cleanup' command)

    SVN更新报错问题(Please execute the 'Cleanup' command) https://segmentfault.com/a/1190000012571289 svn: E20 ...

  10. zynqmp(zcu102rev1.0)系列---1---安装 xsdk

    Xilinx 的zynq7020在设备上面已经使用上,并量产,关于zynq7020使用总结将在近期同步进行. 该系列主要记录Xilinx zynqmp系列 的使用以及在遇到的问题.目前手上有一块dem ...