码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 3484 Showstopper 二分

时间:2014-07-09 09:39:17      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   java   color   strong   



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



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

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

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

POJ 3484 Showstopper 二分

标签:des   style   http   java   color   strong   

原文地址:http://blog.csdn.net/kimi_r_17/article/details/37560135

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!