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. 基于Linux C的socketEthereal程序和Package分析 (一个)

     执行测试平台:CentOS 6.5发行版,内核版本号3.11 1. Linux抓包源程序 在OSI七层模型中.网卡工作在物理层和数据链路层的MAC子层. 进行网络通信时.源主机通过socket( ...

  2. html5 命运之轮生产

    码,如以下: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEn ...

  3. jquery表单过滤器

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  4. 九款免费轻量的 AutoCAD 的开源替代品推荐

    随着各行各业的发展,CAD已经广泛应用于工业.服装.建筑以及电子产业等设计领域.AutoCAD 是一种流行的商业CAD软件,虽然很强大,但并不是免费的.因此本文推荐了几种免费重量轻的CAD工具/软件, ...

  5. C/C++ static用法

    这篇文章没有太多的实际内容,简单记录下static的用法.顺便试一下用markdown来写文章. 1. 在函数中使用 我们都知道在一个函数中的变量是存储在栈区中,函数的每一次调用都伴随着变量的重新定义 ...

  6. sql server 定时备份数据库

    CREATE PROCEDURE [dbo].[SP_DBBackup_EveryNight_Local] @cycle INT, ---保存周期 @IsLocal INT, ---是否为本地 0表示 ...

  7. Win8 Metro(C#)数字图像处理--2.54迭代法图像二值化

    原文:Win8 Metro(C#)数字图像处理--2.54迭代法图像二值化  [函数名称]   迭代法图像二值化      int IterativeThSegment(WriteableBitm ...

  8. HDFS的几点改进

    HDFS(Hadoop Distributed File System)是一个运行在商用机器上面的分布式文件系统,其设计思想来自于google著名的Google File System论文. HDFS ...

  9. SharePoint Add-in Model 介绍 - 引文(先导篇)

    1. SharePoint 平台 如果你已经很熟悉 SharePoint 平台,可跳过本章节. 1.1 SharePoint 是什么 在介绍 Add-in Model 之前,简要提一下 SharePo ...

  10. Flask在VSCODE下基本开发环境配置

    1.创建环境 cd /project/path python3 -m venv venv 第一个VENV是命令,第二个是文件夹名 如果环境不要了,一般做法是直接整个(VENV)文件夹删掉 环境修改下面 ...