POJ 3658 Matrix
Double two points, WA for an afternoon, I really do not understand why a two-point writing will enter the cycle of death.
INF to set a larger, the subject set 0x3f3f3f3f will WA.
There are negative numbers in the subject, the results of two-time (L+R)/2 and (L+R) >>1 are different ;
such as L=0,r=-1, then (l+r)/2=0, and (L+r) >>1=-1, and we need the correct answer is-1, so the first two points must be written (l+r) >>1
The following two kinds of two can be used:
(l+r) >>1
/** Fillname: Two heavy two minutes * created:2016 April 02 14:48 41 seconds Saturday * 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))#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=1e12;//inf to set a larger, the subject set 0x3f3f3f3f will WAConstll 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;intT,n;ll m;ll Cal (ll I,ll j) {//returns the value of the Matrix A[i][j], and the array is hyper-memory returni*i+j*j+100000*i-100000*j+i*j;//int may explode}ll C (ll x) {//The change here to int would be inexplicable WA, and the return value would have to be ll . intL,r,mid2; ll CNT; //It must be here if LLCnt=0; Rep (J,1, n+1) {L=1, r=n+1; while(r>M) {Mid2= (r+l)/2; if(Cal (MID2,J) >=x) R=mid2;//The main requirement is the value of the first M. Elsel=mid2+1; } CNT+=r-1; } returnCNT;}intMain () {ll ub,lb,mid; inch(t); while(t--){ inch(n); Inlld (m); LB=-inf,ub=inf;//inf to set a larger while(ub>lb) {Mid= (ub+lb) >>1;//There are negative numbers that cannot be written (l+r)/2 if(C (mid) >=m) Ub=mid;//The same problem with the median number. ElseLb=mid+1; } OUTLLD (UB-1)///last minus 1}return 0;}
The following can also be used
(L+R)/2
/** Fillname: Two heavy two minutes * created:2016 April 02 14:48 41 seconds Saturday * 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))#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=1e12;//inf to set a larger, the subject set 0x3f3f3f3f will WAConstll 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;intT,n;ll m;ll Cal (ll I,ll j) {//returns the value of the Matrix A[i][j], and the array is hyper-memory returni*i+j*j+100000*i-100000*j+i*j;//int may explode}ll C (ll x) {//The change here to int would be inexplicable WA, and the return value would have to be ll . intL,r,mid2; ll CNT; //It must be here if LLCnt=0; Rep (J,1, n+1) {L=1, r=n+1; while(r>l) {Mid2= (r+l)/2; if(Cal (MID2,J) >=x) R=mid2;//The main requirement is the value of the first M. Elsel=mid2+1; } CNT+=r-1; } returnCNT;}intMain () {ll ub,lb,mid; inch(t); while(t--){ inch(n); Inlld (m); LB=-inf,ub=inf;//inf to set a larger while(ub-lb>1) {Mid= (UB+LB)/2;//There are negative numbers that cannot be written (l+r)/2 if(C (mid) >=m) Ub=mid;//The same problem with the median number. Elselb=mid; } outlld (lb); } return 0;}
Poj3658matrix (double binary + negative + dead loop)