Test instructions: Tell n group a,b,c to generate arithmetic progression according to A + K * C, ask which number in the n set of numbers appear odd several times and appear several times, the topic guarantees that only one such number will appear.
Analysis: Read the question and did not train of thought, then know is a two-minute interval, enumeration is which number appears odd several times, calculate the number before a total number of numbers, if it is odd number, explain the answer in [L, mid].
PS: Before using two points to enumerate the specific requirements of the number, the original enumeration interval can also. When I am two minutes L = mid + 1,r = Mid; (First r = mid + 1,l = Mid is infinite loop, hand count is not wrong?) It's strange ... )
1#include <cstdio>2#include <iostream>3#include <sstream>4#include <cmath>5#include <cstring>6#include <cstdlib>7#include <string>8#include <vector>9#include <map>Ten#include <Set> One#include <queue> A#include <stack> -#include <algorithm> - using namespacestd; the #definell Long Long - #define_cle (M, a) memset (M, A, sizeof (m)) - #defineRepu (I, A, b) for (int i = A; I < b; i++) - #defineREPD (I, A, b) for (ll i = b; i >= A; i--) + #defineSFI (n) scanf ("%d", &n) - #definePFI (n) prllf ("%d\n", N) + #defineINF 0x3f3f3f3f3f A #defineN 20010 at ll A[n],b[n],c[n]; - intN; -ll judge (LL P)///How many flyers have been sent before P ? - { -ll sum =0; -Repu (I,0, N) in { -ll t =min (p,b[i]); to if(T >=A[i]) +Sum + = ((T-a[i])/c[i] +1ll); - } the returnsum%2ll; * } $ intMain ()Panax Notoginseng { - while(~SCANF ("%d",&N)) the { +ll sum = 0ll,t = 0ll,l = Inf,r =0LL; ARepu (I,0, N) the { +scanf"%i64d%i64d%i64d",&a[i],&b[i],&c[i]); -R =Max (r,b[i]); $L =min (l,a[i]); $ } - if(!judge (R)) - { theprintf"DC Qiang is unhappy.\n"); - Continue;Wuyi } thell mid =0LL; - while(L <R) Wu { -Mid = (L + r)/2ll; About if(Judge (mid))///if it's an odd number $R =mid; - Else -L = mid +1ll; - } A ///I beg for specific +sum =0LL; theRepu (I,0, N) - { $ if(R >= A[i] && R <=B[i]) the if((R-a[i])%c[i] = =0) thesum++; the } theprintf"%i64d%i64d\n", r,sum); - } in return 0; the}
View Code
HDU 4768 (sub-interval)