POJ 3484 Showstopper 二分




Showstopper

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1218   Accepted: 356

Description

Data-mining huge data sets can be a painful and long lasting process if we are not aware of tiny patterns existing within those data sets.

One reputable company has recently discovered a tiny bug in their hardware video processing solution and they are trying to create software workaround. To achieve maximum performance they use their chips in pairs and all data objects in memory should have
even number of references. Under certain circumstances this rule became violated and exactly one data object is referred by odd number of references. They are ready to launch product and this is the only showstopper they have. They need
YOU to help them resolve this critical issue in most efficient way.

Can you help them?

Input

Input file consists from multiple data sets separated by one or more empty lines.

Each data set represents a sequence of 32-bit (positive) integers (references) which are stored in compressed way.

Each line of input set consists from three single space separated 32-bit (positive) integers X Y Z and they represent following sequence of references: X, X+Z, X+2*Z, X+3*Z, …, X+K*Z, …(while (X+K*Z)<=Y).

Your task is to data-mine input data and for each set determine weather data were corrupted, which reference is occurring odd number of times, and count that reference.

Output

For each input data set you should print to standard output new line of text with either “no corruption” (low case) or two integers separated by single space (first one is reference that occurs odd number of times and second one is count of that reference).

Sample Input

1 10 1
2 10 1

1 10 1
1 10 1

1 10 1
4 4 1
1 5 1
6 10 1

Sample Output

1 1
no corruption
4 3

Source

Southeastern Europe 2007

题意:根据上面的公式写出历遍次数为奇数的那个数,并且写出它的历遍次数。

思路:这题题目看了好久才看懂,还有那么坑爹的读入,拖了好久,二分查找这个数,它前面的数字历遍次数和必为偶数,后面为奇数。

AC代码:

import java.util.*;

public class Main {
	static int n;

	static int x[];
	static int y[];
	static int z[];
	public static void solve(ArrayList<String> str){
		Scanner scan=new Scanner(System.in);
		n=str.size();
		x=new int[n];
		y=new int[n];
		z=new int[n];
		String s[];
		for(int i=0;i<n;i++){
			s=str.get(i).split(" ");
			x[i]=Integer.parseInt(s[0]);
			y[i]=Integer.parseInt(s[1]);
			z[i]=Integer.parseInt(s[2]);
		}
		long left=1,right =Integer.MAX_VALUE;
		long mid;
		while(left<=right){
			mid=(left+right)/2;
			if(check(mid)%2==1)
				right=mid-1;
			else
				left=mid+1;
		}
		if(left>Integer.MAX_VALUE)
			System.out.println("no corruption");
		else{
			long temp=check(left)-check(left-1);
			System.out.println(left+" "+temp);
		}
	}
	static long check(long mid){
		long ans=0;
		for(int i=0;i<n;i++){
			if(mid>=x[i]) ans+=(Math.min(y[i],mid)-x[i])/z[i]+1;
		}
		return ans;
	}
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		ArrayList<String> str=new ArrayList<String>();
		String s=null;
		while(scan.hasNext()){
			while(scan.hasNext()&&!(s=scan.nextLine()).equals(""))
				str.add(s);
			solve(str);str.clear();
			while(scan.hasNext()&&(s=scan.nextLine()).equals(""));
			str.add(s);
		}
	}

}

POJ 3484 Showstopper 二分,布布扣,bubuko.com

时间: 2024-11-19 02:55:49

POJ 3484 Showstopper 二分的相关文章

POJ 3484 Showstopper(二分答案)

[题目链接] http://poj.org/problem?id=3484 [题目大意] 给出n个等差数列的首项末项和公差.求在数列中出现奇数次的数.题目保证至多只有一个数符合要求. [题解] 因为只有一个数符合要求,所以在数列中数出现次数的前缀和必定有奇偶分界线, 所以我们二分答案,计算前缀和的奇偶性进行判断,得到该数的位置. [代码] #include <cstdio> #include <algorithm> #include <cstring> using na

poj 3484 Showstopper

Showstopper Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2057   Accepted: 612 Description Data-mining huge data sets can be a painful and long lasting process if we are not aware of tiny patterns existing within those data sets. One r

POJ - 3484 Showstopper 二分搜索

题目大意:给出N个X Y Z组合,其中X Y Z组合能够输出 X, X + Z, X + 2 * Z- X + K * Z(X+K * Z <= Y)问这些输出的数中,有哪个数是输出奇数次的 解题思路:输出保证最多只有一个奇数 假设J是输出奇数次的那个数,那么小于J的所有输出的数的个数之和就为偶数,大于等于J的所有输出的数的个数之和为奇数 如果以i为标准,输出小于等于i的所有数之和,i从小到大变化的话,就会有如下的形式 偶偶偶偶偶偶奇奇奇...第一个奇刚好是J (具体的可以自己验证) 通过上面的

poj 1469 COURSES (二分匹配)

COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16877   Accepted: 6627 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is poss

POJ 2398 计算几何+二分+排序

Toy Storage Time Limit: 1000MS  Memory Limit: 65536K Total Submissions: 3953  Accepted: 2334 Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box t

poj 3104 Drying (二分)

/*设某次二分出的一个值是mid: 1.对于一件ai值小于等于mid的衣服,直接晾干即可: 2.对于一件ai值大于mid值的衣服,最少的用时是用机器一段时间, 晾干一段时间,设这两段时间分别是x1和x2, 那么有mid=x1+x2,ai<=k*x1+x2,解得x1>=(ai-mid)/(k-1) , 所以对(ai-mid)/(k-1)向上取整就是该件衣服的最少用时.*/ # include <stdio.h> # include <string.h> # include

poj 1151 Atlantis 二分查找+离散化

Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17464   Accepted: 6654 Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of

POJ 2318 计算几何+二分

TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10425 Accepted: 5002 Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away when

POJ 3122 Pie 二分答案

Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9653   Accepted: 3478   Special Judge Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of v