HDU 5178
Beg |a[i]-a[j]| <= K (i < J) <i,j> logarithm, at the beginning that the data is not very direct ans++, and then the results come out to know, ah Ah ah, too young too simple. Anyway, a lesson.
Idea: Sort first, then use binary search to find A[i] + K in the array position, then ans add
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<cstdlib>#include<stack>#include<cctype>#include<string>#include<malloc.h>#include<queue>#include<map>using namespacestd;Const intINF =0xFFFFFF;Const DoubleESP = 10e-8;Const DoublePi =4* ATAN (1.0);Const intMAXN =100000+Ten;Const Long LongMoD =1000000007;Const intDr[] = {1,0,-1,0,-1,1,-1,1};Const intDc[] = {0,1,0,-1,1,-1,-1,1};typedefLong LongLL; ll GAC (ll A,ll b) {returnB?GAC (b,a%b): A;}Long LongA[MAXN];intMain () {#ifndef Online_judge freopen ("Inpt.txt","R", stdin); //freopen ("Output.txt", "w", stdout);#endif intT; intn,k; scanf ("%d",&t); while(t--) {scanf ("%d%d",&n,&k); Memset (A,0,sizeof(a)); for(inti =0; I < n;i++) {scanf ("%i64d",&A[i]); } sort (A,a+N); Long LongAns =0; for(inti =0; i < n-1; i++){ Long LongTMP = A[i] +K; intm = Upper_bound (a,a+n,tmp)-A; Ans+ = (m-i-1); } printf ("%i64d\n", ans); } return 0;}View Code
HDU 5179
Test instructions is: a number if its lower than equal to the high level, and the high is the number of adjacent position of the integer times is called the charm of numbers, require to find out the number of beautiful numbers in the [L,r] range
Ideas, DFS violence.
Did the second question ~ ~
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<cstdlib>#include<stack>#include<cctype>#include<string>#include<malloc.h>#include<queue>#include<map>using namespacestd;Const intINF =0xFFFFFF;Const DoubleESP = 10e-8;Const DoublePi =4* ATAN (1.0);Const intMAXN =100000+Ten;Const Long LongMoD =2147483647;Const intDr[] = {1,0,-1,0,-1,1,-1,1};Const intDc[] = {0,1,0,-1,1,-1,-1,1};typedefLong LongLL; ll GAC (ll A,ll b) {returnB?GAC (b,a%b): A;}intL,r;inta[ -],b[ -];intarr[ -];intCNT;Long LongGet_num (intx) { Long LongTMP =0; for(inti = X1; i >0; i--) {tmp= tmp *Ten+Arr[i]; } //cout << tmp << Endl; returntmp;}voidDfsintx) { Long Longtt =get_num (x); if(TT >R)return; if(TT >=L) CNT++; for(inti =1; I <Ten; i++){ intTMP = arr[x-1] *i; if(TMP <Ten) {Arr[x]=tmp; DFS (x+1); } Arr[x]=0; }}intMain () {#ifndef Online_judge freopen ("Inpt.txt","R", stdin);#endif intT; scanf ("%d",&t); while(t--) {scanf ("%d%d",&l,&R); memset (arr,0,sizeof(arr)); CNT=0; arr[0] =1; DFS (1); printf ("%d\n", CNT); } return 0;}
The third question and so on did not make out ...
Bestcoder Round #31