Codeforces Gym101097I:Sticks (思维)
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 (思维)的更多相关文章
- CodeForces 604C 【思维水题】`
题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次 ...
- Minimum Integer CodeForces - 1101A (思维+公式)
You are given qq queries in the following form: Given three integers lili, riri and didi, find minim ...
- Codeforces 1038D - Slime - [思维题][DP]
题目链接:http://codeforces.com/problemset/problem/1038/D 题意: 给出 $n$ 个史莱姆,每个史莱姆有一个价值 $a[i]$,一个史莱姆可以吃掉相邻的史 ...
- AND Graph CodeForces - 987F(思维二进制dfs)
题意:给出n(0≤n≤22)和m,和m个数ai,1 ≤ m ≤ 2n ,0≤ai<2n ,把ai & aj == 0 的连边,求最后有几个连通块 解析:一个一个去找肯定爆,那么就要转换一 ...
- CodeForces - 631C ——(思维题)
Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...
- codeforces 571A--Lengthening Sticks(组合+容斥)
A. Lengthening Sticks time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Almost Acyclic Graph CodeForces - 915D (思维+拓扑排序判环)
Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megaby ...
- Diagonal Walking v.2 CodeForces - 1036B (思维,贪心)
Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point ( ...
- CodeForces - 1102A(思维题)
https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...
随机推荐
- jquery腾讯微博
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 定长文本格式编辑神器 - Record Editor
由于项目里有系统使用的是定长的文本格式,如果列数比较多的话编辑检查起来会特别麻烦.之前也找了各种编辑器的插件,最多只能显示列宽.辅助线而以还是不方便 .最后发现了一个开源项目 Record Edito ...
- MVVM模式的几个开源框架
原文:MVVM模式的几个开源框架 实现MVVM的框架有很多,如: • MVVM Light Toolkit: http://mvvmlight.codeplex.com • Microsoft Pri ...
- 图像滤镜艺术---流行艺术风滤镜特效PS实现
原文:图像滤镜艺术---流行艺术风滤镜特效PS实现 今天,本人给大家介绍一款新滤镜:流行艺术风效果,先看下效果吧! 原图 流行艺术风效果图 上面的这款滤镜效果是不是很赞,呵呵,按照本人以往的逻辑,我会 ...
- 浏览器中实现3D全景浏览
如果你用过网页版的百度地图,你大概3D全景图浏览是一种怎样的酷炫体验:在一个点可以360度环顾周围的建筑.景色,当然也可以四周移动,就像身临其境. 科普 全景图共分为三种: ①球面全景图 利用一张全景 ...
- 常用json解析库比较及选择 fastjson & gson
一.常用json解析库比较及选择 1.简介 fastjson和gson是目前比较常用的json解析库,并且现在我们项目代码中,也在使用这两个解析库. fastjson 是由阿里开发的,号称是处理jso ...
- How to Capture the Integer-Divide-By-Zero Error in C++(提前定义信号)
How to Capture the Integer-Divide-By-Zero Error in C++? MANUAL CAPTURE The simple and straightforwar ...
- Delphi xe5 StyleBook的用法(待续)
首先要在FORM里拖进来一个StyleBook1,然后在Form里设置属性,记住一定要在单击form,在OBject Inspector里设置StyleBook [StyleBook1]. 下一个属 ...
- 配置我的Ubuntu Server记(包括桌面及VNC,SSH,NTP,NFS服务) good
跟老板申请买了一台配置相对较好的计算机回来做GPU计算,当然,不能独享,所以做成服务器让大家都来用. 这篇日志用来记录配置过程中遇到的一些问题,以方便下次不需要到处谷歌度娘. 安装Server版系统 ...
- 通过内核对象在服务程序和桌面程序之间通信的小问题 good
关于在通过 事件对象 在服务程序和普通桌面应用程序相互之间通信的问题,分类情况进行讨论:1.普通桌面应用程序中创建事件,服务程序中打开事件 XP的情况普通桌面应用程序中创建: m_hEvent = : ...