1. 程式人生 > >POJ 3484 二分字首和

POJ 3484 二分字首和

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

題意:每次給出三個數x,y,z,用這三個數構成一個等差數列,x為首項,y是末項,z是公差,總共給出n組x,y,z( n待定),求這n組數列中出現次數為奇數的那個數以及該數出現的次數(保證最多有一個數出現的次數為奇數)

 

 

沒有辦法去暴力,所有的數值只知道是在int範圍內,但是開到陣列很大,並且還要是long long 的型別,否則會WA,還有就是如何輸入的問題,用到了sscanf,把前提解決了,剩下的就是用二分列舉答案了;

在這裡mid列舉的是出現奇數次的數字,然後根據等差數列的定理,可以算出大於首項x的mid的前面的數字有多少個。。。,有點繞,就是比如給1 10 1 ,mid=5,那麼就需要算出mid(包括)前面有多少個數(因為題目中保證只有一個答案,所以不妨就用字首和單調的方法來解決,那麼假設x就是那個奇數個數的數,x之間的數應該都是出現了偶數次,依據這個不斷壓縮左端點,也就是最大值),如果將所有的n組數列求完之後小於mid的數有奇數個,那就繼續壓縮資料取值域,縮小右區間就好。