POJ3484 Showstopper (two points + string processing)

Source: Internet
Author: User

POJ3484 Showstopper

Main topic:

Given three x x, Y, Z, with these three numbers to form a arithmetic progression, the X. is the first, Y is the last, Z is the tolerance

Give a total of n x, y, Z (n tbd) to the number of odd occurrences in the n set of numbers and the number of occurrences (guaranteed to have an odd number of occurrences)

  The first is the processing of strings and the finding of n

  

  has not been how to contact the string, at first do not know how to read the data, after looking at Daniel's code, know sscanf () This function magical usage, the data read into the basic copy Daniel's code come over,

For the final data of the judgment is not clear, no final judgment will WA, and there is all the data preferably with a long long,

Two points are basically used by their own template, for this type of integer two, now write two points is no longer the same as a few days ago, there is always a cycle of death

The mid of the two-point enumeration is an odd number of occurrences,

The method is to add the total number of prefixes and occurrences, the number of less than the correct value will appear even several times, when the value of the enumeration is less than the correct value, the prefix and add an even number,

  When the value of the enumeration is greater than or equal to the correct value, the prefix and the sum are odd, sum&1, Ub=mid, and finally C (UB)-C (ub-1) to get the number of mid occurrences;

  

/** created:2016 April 03 20:06 30 Second Sunday * author:akrusher**/#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctime>#include<iostream>#include<algorithm>#include<string>#include<vector>#include<deque>#include<list>#include<Set>#include<map>#include<stack>#include<queue>#include<numeric>#include<iomanip>#include<bitset>#include<sstream>#include<fstream>using namespacestd;#defineRep (i,a,n) for (int i=a;i<n;i++)#definePer (i,a,n) for (int i=n-1;i>=a;i--)#defineIn (n) scanf ("%d",& (n))#defineIn2 (X1,X2) scanf ("%d%d",& (x1),& (x2))#definein3 (X1,X2,X3) scanf ("%d%d%d",& (x1),& (x2),& (x3))#defineINLL (n) scanf ("%i64d",& (n))#defineInll2 (X1,X2) scanf ("%i64d%i64d",& (x1),& (x2))#defineINLLD (n) scanf ("%lld",& (n))#defineInlld2 (X1,X2) scanf ("%lld%lld",& (x1),& (x2))#defineINF (n) scanf ("%f",& (n))#defineInf2 (X1,X2) scanf ("%f%f",& (x1),& (x2))#defineINLF (n) scanf ("%lf",& (n))#defineINLF2 (X1,X2) scanf ("%lf%lf",& (x1),& (x2))#defineInc (STR) scanf ("%c",& (str))#defineINS (str) scanf ("%s", (str))#defineOut (x) printf ("%d\n", (x))#defineOut2 (x1,x2) printf ("%d%d\n", (x1), (x2))#defineOutf (x) printf ("%f\n", (x))#defineOUTLF (x) printf ("%lf\n", (x))#defineOUTLF2 (x1,x2) printf ("%lf%lf\n", (x1), (x2));#defineOUTLL (x) printf ("%i64d\n", (x))#defineOUTLLD (x) printf ("%lld\n", (x))#defineOUTC (str) printf ("%c\n", (str))#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#defineSZ (x) ((int) (x). Size ())#defineMem (x, y) memset (x,y,sizeof (×));typedef vector<int>Vec;typedefLong LongLl;typedef pair<int,int>P;Const intdx[4]={1,0,-1,0},dy[4]={0,1,0,-1};Constll inf=1ll<< -;//directly with 1 shift will explode intConstll mod=1e9+7; ll Powmod (ll A,ll b) {ll res=1; a%=mod; for(; b;b>>=1){if(b&1) Res=res*a%mod;a=a*a%mod;}returnRes;}Const BOOLAc=true;Const intM_case=1000000+ -; ll X[m_case],y[m_case],z[m_case];//arithmetic progression, x First, y is last, Z is tolerancell CNT;Charstr[ the];//Even even occasionally even odd (mid) Chichichchichll C (ll mid) {//return value with LL, otherwise it will WAll sum=0, temp; Rep (I,0, CNT) {        if(Mid<x[i])Continue; Temp=min (Mid,y[i])-X[i]; Sum+=temp/z[i]+1;//the number of prefixes and occurrences, including the current        }    returnsum;//odd is true;}voidsolve () {ll lb,mid,ub; LB=1ll,ub=INF;  while(ub>lb) {Mid= (Lb+ub) >>1; if(C (Mid) &1) ub=mid; ElseLb=mid+1; }    if(Lb==inf) printf ("No corruption\n"); Elseprintf"%lld%lld\n", Ub,c (UB)-C (ub-1));//Number of calculations}intMain () {CNT=0;  while(Gets (str)! =NULL) {         if(strlen (str) = =0){            if(cnt==0)Continue;//Note that there may be more lines of space between the input datasolve (); CNT=0; }         Else{sscanf (str,"%i64d%i64d%i64d",&x[cnt],&y[cnt],&z[cnt]); CNT++; }    }    if(CNT) solve ();//must be judged, otherwise it will WA    return 0;}

POJ3484 Showstopper (two points + string processing)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.