F. The Weakest Sith----排序水题

F. The Weakest Sith
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In a galaxy far, far away the great galactic empire had collapsed after the death of the emperor, and now a new corrupted galactic republic gradually grows stronger. But the evil Sith don't spend time in vain: they've created opposition named «The last order» and now they are planning to choose a leader by a fair tournament.

In the tournament there will be n Siths who has left alive. The i-th of these Siths has three integer characteristics: mastery of lightsabers ai, mastery of the Force bi and the level of mental balance ci. All characteristics of all Siths are different. The tournament consists of one on one fights. The winner of each of these fights is the Sith who has at least two characteristics that are bigger than their opponent's corresponding ones.

The problem is that the Sith tournaments have never been organized to find the strongest Sith who could beat anyone else: instead, they were supposed to distinguish the weakest one, somebody who couldn't win any fight, and to let everybody take a good laugh at that loser. It seems like such Sith will become the leader of «The last order», so it'd be good to know them in advance.

Input

The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of the Siths who will participate in the tournament.

Each of the next n lines contains three space-separated integers: aibici (1 ≤ ai, bi, ci ≤ 109) — the three corresponding characteristics of the i-th Sith.

Output

In the first line output a single integer — the number of Siths who can't win any fight.

In the second line print the numbers of those Siths separated by a space.

Examples
input
4
3 11 9
1 4 8
5 2 10
12 7 6
output
1
2
input
3
700 40 1
50 2 800
3 900 60
output
0

题目链接:http://codeforces.com/gym/101149/problem/F


每个人有三个值,各不相同,两两PK ,两个值大的人获胜,不会出现平局,求输掉所有局的人。


排序水一下就好了。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
struct node{
	LL a,b,c,id;
}xin[300000];
bool cmp(struct node a,struct node b){
	int ans=0;
	if(a.a>b.a)
		ans++;
	if(a.b>b.b)
		ans++;
	if(a.c>b.c)
		ans++;
	if(ans<2)
		return false;
    return true;
}
bool judge(struct node a,struct node b){
    int ans=0;
	if(a.a>b.a)
		ans++;
	if(a.b>b.b)
		ans++;
	if(a.c>b.c)
		ans++;
	if(ans<2)
		return false;
    return true;
}
int main(){
	int n;
	while(~scanf("%d",&n)){
        for(int i=0;i<n;i++){
            scanf("%lld%lld%lld",&xin[i].a,&xin[i].b,&xin[i].c);
            xin[i].id=i+1;
        }
        sort(xin,xin+n,cmp);
        struct node t=xin[n-1];
        bool flag=true;
        for(int i=0;i<n-1;i++){
            if(judge(t,xin[i])){
                flag=false;
                break;
            }
        }
        if(flag){
            cout<<1<<endl;
            printf("%lld\n",xin[n-1].id);
        }
        else{
            printf("0\n");
        }
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Jonathan is fighting against DIO's Vampire minions. There are n of them with strengths a1,a2,…,an. Denote (l,r) as the group consisting of the vampires with indices from l to r. Jonathan realizes that the strength of any such group is in its weakest link, that is, the bitwise AND. More formally, the strength level of the group (l,r) is defined as f(l,r)=al&al+1&al+2&…&ar. Here, & denotes the bitwise AND operation. Because Jonathan would like to defeat the vampire minions fast, he will divide the vampires into contiguous groups, such that each vampire is in exactly one group, and the sum of strengths of the groups is minimized. Among all ways to divide the vampires, he would like to find the way with the maximum number of groups. Given the strengths of each of the n vampires, find the maximum number of groups among all possible ways to divide the vampires with the smallest sum of strengths. Input The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer n (1≤n≤2⋅105) — the number of vampires. The second line of each test case contains n integers a1,a2,…,an (0≤ai≤109) — the individual strength of each vampire. The sum of n over all test cases does not exceed 2⋅105. Output For each test case, output a single integer — the maximum number of groups among all possible ways to divide the vampires with the smallest sum of strengths.c++实现
最新发布
07-07

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值