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



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

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

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);
		}
	}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值