Test instructions: Give you 10W numbers, each number is a large number, the range is 1 to 10^30, and then ask you how many ways, each time you choose two number, two number and 2 power
The following: 10 of 30 times is about 2 100 times, so first pre-processing 2 102 times, then each input a large number, enumeration 2 power to reduce it, and then go to map to find how many solutions, in fact, is a very simple idea, but I have been writing fried, mainly large number of templates is too poor, will T, plus my IQ offline , opened a very large array to deposit the input content, the result of the strength T.
In fact, one side of the input, and then converted to a large number, and then enumerate 2 power, subtract, and then hash, go to map inside, and then accumulate sum, and then put the input hash, put into the map, so good
Asked QWB god Ben to a new posture of the large number of template Otz, feel very dick, run fast
#include <map> #include <set> #include <stack> #include <queue> #include <cmath> #include <string> #include <vector> #include <cstdio> #include <cctype> #include <cstring># Include <sstream> #include <cstdlib> #include <iostream> #include <algorithm> #pragma comment ( linker, "/stack:102400000,102400000") using namespace std; #define MAX 100005//#define MAXN 500005#de Fine Maxnode 105#define sigma_size 2#define lson l,m,rt<<1#define Rson M+1,R,RT&L T;<1|1#define LRT rt<<1#define RRT rt<<1|1#define Middle int m= (r+l) >&G T;1#define LL long long#define ull unsigned long long#define mem (x,v) memset (x,v,sizeof (x) ) #define LOWBIT (x) (x&-x) #define PII pair<int,int> #define BITS (a) __builtin_popcount (a ) #define MK Make_pair#define limit 10000//const int prime = 999983;const int INF = 0x3f3f3f3f;const LL inff = 0x3f3f;const double pi = ACOs ( -1.0); const double inf = 1e18;const double eps = 1e-9;const LL mod = 1e9+7;const ull mx = 1e9+7; /*****************************************************/inline void RI (int &x) {char C; while (C=getchar ()) < ' 0 ' | | c> ' 9 '); x=c-' 0 '; while ((C=getchar ()) >= ' 0 ' && c<= ' 9 ') x= (x<<3) + (x<<1) +c-' 0 ';} /*****************************************************/const int MX = 10;//Altogether can represent the length of the Mx*dlen const int MAXN = 9999;const int Dlen = 4;//How many digits are placed inside an int char ret[105];class Big {public:int a[mx], Len; Big (const int b = 0) {int c, d = b; len = 0; memset (A, 0, sizeof (a)); while (d > maxn) {c = d-(d/(MAXN + 1)) * (MAXN + 1); D = d/(MAXN + 1); a[len++] = c; } a[len++] = D; } Big (const char *s) {int T, K, index,L, I; memset (A, 0, sizeof (a)); L = strlen (s); len = L/dlen; if (L% dlen) len++; index = 0; for (i = L-1; I >= 0; I-= Dlen) {t = 0; K = I-dlen + 1; if (k < 0) k = 0; for (int j = k; J <= I; j + +) {t = T * + s[j]-' 0 '; } a[index++] = t; }} big operator/(const int &b) const {BIG ret; int I, down = 0; for (int i = len-1; I >= 0, i--) {ret.a[i] = (A[i] + down * (MAXN + 1))/b; Down = a[i] + down * (MAXN + 1)-ret.a[i] * b; } Ret.len = Len; while (ret.a[ret.len-1] = = 0 && ret.len > 1) ret.len--; return ret; } bool Operator> (const BIG &t) const {INT ln; if (len > T.len) return true; else if (len = = t.len) {ln = len-1; while (a[ln] = = T.a[ln] && ln >= 0) ln--; if (ln; = 0 && A[ln] > T.a[ln]) return true; else return false; } else return false; } Big operator+ (const big &t) const {Big T (*this); int I, big; Big = T.len > len? T.len:len; for (i = 0; i < big; i++) {T.a[i] + = T.a[i]; if (T.a[i] > Maxn) {t.a[i + 1]++; T.a[i]-= MAXN + 1; }} if (T.a[big]! = 0) T.len = big + 1; else T.len = big; return t; } Big operator-(const big &t) const {int I, j, big; BOOL Flag; Big T1, T2; if (*this > T) {t1 = *this; t2 = T; Flag = 0; } else {t1 = T; t2 = *this; flag = 1; } big = T1.len; for (i = 0; i < big; i++) {if (T1.a[i] < T2.a[i]) {j = i + 1; while (t1.a[j] = = 0) j + +; t1.a[j--]--; While(J > I) t1.a[j--] + = MAXN; T1.a[i] + = MAXN + 1-t2.a[i]; } else t1.a[i]-= t2.a[i]; } T1.len = big; while (t1.a[t1.len-1] = = 0 && t1.len > 1) {t1.len--; big--; } if (flag) t1.a[big-1] = 0-t1.a[big-1]; return t1; } int operator% (const int &b) const {int I, d = 0; for (int i = len-1; I >= 0; i--) {d = ((d * (MAXN + 1)% B + a[i])% B; } return D; } Big operator* (const big &t) const {BIG ret; int I, J, up, temp, temp1; for (i = 0; i < len; i++) {up = 0; for (j = 0, J < T.len; J + +) {temp = a[i] * T.a[j] + ret.a[i + j] + up; if (Temp > maxn) {temp1 = temp-temp/(MAXN + 1) * (MAXN + 1); Up = temp/(MAXN + 1); Ret.a[i + j] = Temp1; } else {up= 0; Ret.a[i + j] = temp; }} if (up! = 0) {ret.a[i + j] = up; }} Ret.len = i + j; while (ret.a[ret.len-1] = = 0 && ret.len > 1) ret.len--; return ret; } ull print () {ull ret=0; for (int i=len-1;i>=0;i--) ret=ret*mx+a[i]; return ret; }}pow2[105],ss;map<ull,int> Ma;char s[105];void init () {pow2[0]=1; for (int i=1;i<=103;i++) pow2[i]=pow2[i-1]*2;} int main () {//freopen ("test.txt", "R", stdin); int t; cin>>t; Init (); while (t--) {int n; cin>>n; Ma.clear (); LL ans=0; for (int i=0;i<n;i++) {scanf ("%s", s); int Len; Ss=s; for (int j=103;j>=1;j--) {if (POW2[J]>SS) {Big cnt=pow2[j]-ss; Ull temp=cnt.print (); if (Ma.count (temp)) ans+=ma[temp]; }} ull tmp=ss.print (); if (!ma.count (TMP)) ma[tmp]=0; ma[tmp]++; cout<<ma[ss[i]]<< "" <<ss[i]<<endl; } cout<<ans<<endl; } return 0;} /************************************************************** problem:1720 User:1403mashaonan language:c++ result:accepted time:5640 Ms memory:4272 kb****************************************************************/
CSU 1720 How to Get 2^n (large number +hash)