CodeForces 23C Oranges and Apples 抽屉原理

题目链接:点击打开链接

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <math.h>
using namespace std;
#define inf 10000000
#define ll __int64
#define N 200005

ll n, m, v;
struct node{
	int a,b,pos;
	bool operator<(const node&x)const{
		return a!=x.a?a<x.a:b<x.b;
	}
}f[N];
int ans[N];
int main(){
	ll i, j, T; cin>>T;
	while(T--){
		cin>>n;
		ll all = 2*n-1;
		for(i=1;i<=all; i++){
			cin>>f[i].a>>f[i].b;
			f[i].pos = i;
		}
		sort(f+1,f+all+1);
		ll top = 0;
		for(i=1;i<all; i+=2)
			if(f[i].b >= f[i+1].b)
				ans[top++]=f[i].pos;
			else ans[top++] = f[i+1].pos;
			ans[top++]=f[all].pos;
			puts("YES");
			sort(ans,ans+top);
			for(i=0;i<top;i++)
				printf("%d%c",ans[i],i==top-1?'\n':' ');
	}
	return 0;
}
/*
3
40 -83
52 -80
-21 -4

*/

CodeForces 23C Oranges and Apples 抽屉原理,布布扣,bubuko.com

时间: 2024-08-08 05:18:45

CodeForces 23C Oranges and Apples 抽屉原理的相关文章

codeforces #319 B - Modulo Sum (抽屉原理,dp)

B - Modulo Sum Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description You are given a sequence of numbers a1, a2, ..., an, and a number m. Check if it is possible to choose a non-empty subsequence aij 

Codeforces Round #325 (Div. 2) E. Alice, Bob, Oranges and Apples

E. Alice, Bob, Oranges and Apples Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining frui

POJ 3370 Halloween treats(抽屉原理)

Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6631   Accepted: 2448   Special Judge Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets

容斥原理和抽屉原理

转自:http://www.exam8.com/zige/gongwuyuan/xingzheng/sl/201408/2984187.html 一.容斥原理 在计数时,要保证无一重复,无一遗漏.为了使重叠部分不被重复计算,在不考虑重叠的情况下,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计算的数目排斥出去,使得计算的结果既无遗漏又无重复,这种计数的方法称为容斥原理. 1.容斥原理1——两个集合的容斥原理 如果被计数的事物有A.B两类,那么,先把A.B两个集合的元素个数相加,发

POJ 3370 Halloween treats(抽屉原理)

题意  有c个小孩 n个大人万圣节搞活动  当小孩进入第i个大人家里时   这个大人就会给小孩a[i]个糖果  求小孩去哪几个大人家可以保证得到的糖果总数是小孩数c的整数倍  多种方案满足输出任意一种 用s[i]表示前i个打人给糖果数的总和  令s[0]=0  那么s[i]共有n+1种不同值  而s[i]%c最多有c种不同值  题目说了c<=n   所以s[i]%c肯定会有重复值了 这就是抽屉原理了   n个抽屉放大于n个苹果   至少有一个抽屉有大于等于2个苹果 就把s[i]%c的取值个数(c

51NOD 1103 N的倍数(抽屉原理)

传送门 一个长度为N的数组A,从A中选出若干个数,使得这些数的和是N的倍数. 例如:N = 8,数组A包括:2 5 6 3 18 7 11 19,可以选2 6,因为2 + 6 = 8,是8的倍数. Input 第1行:1个数N,N为数组的长度,同时也是要求的倍数.(2 <= N <= 50000) 第2 - N + 1行:数组A的元素.(0 < A[i] <= 10^9) Output 如果没有符合条件的组合,输出No Solution. 第1行:1个数S表示你所选择的数的数量.

51nod 1103 N的倍数 (抽屉原理)

题目链接:传送门 题意: 略. 分析: 把前缀和统计出来对n取模,任意连个相等的sum[i],sum[j],[i,j]内的数的和都满足这个条件. n个数对n取模,范围为[0~n-1],由抽屉原理可知,最少有一个数模n=0,或者两个数模n相等. 代码如下: #include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 50010; LL a[maxn],sum[maxn]; int mai

CodeForces 449C Jzzhu and Apples 数学+素数

这道题目晚上本来就花了很多把都××了,着实觉得自己思路没错啊,回顾一下思路,给你n个数,分成两两组合一对,分成最多组如何分,但是组合的两个数 不能互素,所以呢 偶数肯定是好的了,所以先放着,先把素数给搞定,10^5所以枚举所有包含该素数因子的数,如果刚好分组则最好,不然的话其中有偶数的踢掉一个给下面的偶数处理部分,最后再处理偶数的部分,这样肯定满足组数最多,完全没有问题,后来方法确实是没问题啊,只是代码有问题,我靠!真是脑残!,今天看到一位大牛的想法,我跟他是一样的,只是代码写搓了,后来改了又改

POJ 2356 Find a multiple 抽屉原理

从POJ 2356来体会抽屉原理的妙用= =! 题意: 给你一个n,然后给你n个数,让你输出一个数或者多个数,让这些数的和能够组成n: 先输出一个数,代表有多少个数的和,然后再输出这些数: 题解: 首先利用前缀和先预处理一下,然后如果sum[i]==0的话,很显然就直接输出i,然后接下来从第一位一直输出到第i位就行了 然后接下来直接用一个mod数组表示上一个答案为这个mod的时候的编号是多少 就是mod[sum[i]%n]=i; 然后判断一下if(mod[sum[i]%n]!=0)然后就直接从m