列出個方程枚舉解一下c++
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 4005 #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int64 N; void Solve() { read(N); for(int64 i = 1 ; i <= 3500 ; ++i) { for(int64 j = 1 ; j <= 3500 ; ++j) { int64 t = 4 * i * j - N * j - N * i; if(t <= 0) {continue;} int64 s = N * i * j; if(s % t == 0) { out(s / t);space;out(i);space;out(j);enter; return ; } } } } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
每次刪掉一個lowbit,而後加上這個lowbit - 1
這樣的話咱們每次求一遍知足是這個數子集的數的和就好了數組
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 100005 #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N,K; int A[MAXN],B[MAXN]; int64 ans; int lowbit(int x) { return x & (-x); } void Calc(int v) { int64 res = 0; for(int i = 1 ; i <= N ; ++i) { if((v & A[i]) == A[i]) res += B[i]; } ans = max(ans,res); } void Solve() { read(N);read(K); for(int i = 1 ; i <= N ; ++i) { read(A[i]);read(B[i]); } Calc(K); while(K) { int t = lowbit(K); int h = K - 1; K -= t; Calc(h); } out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
又是幾何題。。。
二分次數150WA了改爲200過了orz
確定是這些點的橫座標的中位數和縱座標的中位數
而後咱們用縱座標距離,二分一個數,畫一條平行於x軸的線
而後求出交點,把每條線的交點從小到大排序,每條線能相交且在這個縱座標值如下的線就是交點橫座標比它小且幅角比它大
樹狀數組維護一下就好了ui
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 40005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } const db PI = acos(-1.0); int N,id[MAXN],tr[MAXN]; int64 ALL; db A[MAXN],B[MAXN],C[MAXN]; pair<db,int> t[MAXN]; int lowbit(int x) { return x & (-x); } void Insert(int x) { while(x <= N) { tr[x]++; x += lowbit(x); } } int Query(int x) { int res = 0; while(x > 0) { res += tr[x]; x -= lowbit(x); } return res; } bool dcmp(db a,db b) { return fabs(a - b) < eps; } void Calc_y() { for(int i = 1 ; i <= N ; ++i) { t[i] = mp(atan2(-A[i],B[i]),i); if(t[i].fi < 0) t[i].fi += PI; } sort(t + 1,t + N + 1); for(int i = 1 ; i <= N ; ++i) id[t[i].se] = i; db L = -1e9,R = 1e9; int cnt = 200; while(cnt--) { db mid = (L + R) * 0.5; int64 res = 0; for(int i = 1 ; i <= N ; ++i) { t[i] = mp((C[i] - B[i] * mid) / A[i],id[i]); } sort(t + 1,t + N + 1); int p = N + 1; memset(tr,0,sizeof(tr)); for(int i = N ; i >= 1 ; --i) { if(i != N && !dcmp(t[i + 1].fi,t[i].fi)) { res += 1LL * (p - i - 1) * (p - i - 2) / 2; for(int j = p - 1 ; j >= i + 1; --j) { Insert(t[j].se); } p = i + 1; } res += Query(t[i].se - 1); } res += 1LL * (p - 1) * (p - 2) / 2; if(res >= (ALL + 1) / 2) R = mid; else L = mid; } printf("%.10lf",R); } void Calc_x() { for(int i = 1 ; i <= N ; ++i) { t[i] = mp(atan2(-A[i],B[i]),i); if(t[i].fi < 0) t[i].fi += PI; if(t[i].fi * 2 > PI) t[i].fi -= PI; } sort(t + 1,t + N + 1); for(int i = 1 ; i <= N ; ++i) id[t[i].se] = i; db L = -1e9,R = 1e9; int cnt = 200; while(cnt--) { db mid = (L + R) * 0.5; int64 res = 0; for(int i = 1 ; i <= N ; ++i) { t[i] = mp((C[i] - A[i] * mid) / B[i],id[i]); } sort(t + 1,t + N + 1); int p = 0; memset(tr,0,sizeof(tr)); for(int i = 1 ; i <= N ; ++i) { if(i != 1 && !dcmp(t[i - 1].fi,t[i].fi)) { res += 1LL * (i - 1 - p) * (i - 1 - p - 1) / 2; for(int j = p + 1 ; j <= i - 1 ; ++j) { Insert(t[j].se); } p = i - 1; } res += Query(t[i].se - 1); } res += 1LL * (N - p) * (N - p - 1) / 2; if(res >= (ALL + 1) / 2) R = mid; else L = mid; } printf("%.10lf",R); } void Solve() { read(N); for(int i = 1 ; i <= N ; ++i) { scanf("%lf%lf%lf",&A[i],&B[i],&C[i]); } ALL = 1LL * N * (N - 1) / 2; Calc_x();space;Calc_y();enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
有點神奇
咱們根據歐拉定理,能夠有
\(a^k \equiv a^{\varphi(m) + k % \varphi(m)} \pmod m\)
而後k若是大到必定程度,兩個數\(a^{x}\)和\(a^{y}\)相同就是\(x\)和\(y\)在取模\(\varphi(m)\)意義下相同
設置他們都大於100
而後須要知足
\(x \equiv A^{y} \pmod M\)
\(x \equiv y \pmod {\varphi(m)}\)
根據擴歐,咱們須要有
\(A^y \equiv y \pmod {gcd(M,\varphi(m))}\)
這個能夠遞歸下去
而後假如咱們求出了這個y
咱們就能夠代入原來的式子,解出一個x
若是x不夠大,咱們能夠加上咱們取模的數字,直到x大於100spa
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 40005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int64 A,M; int64 phi(int64 x) { int64 t = x; for(int i = 2 ; i <= x / i ; ++i) { if(x % i == 0) { t = t / i * (i - 1); while(x % i == 0) x /= i; } } if(x > 1) t = t / x * (x - 1); return t; } int64 gcd(int64 a,int64 b) { return b == 0 ? a : gcd(b,a % b); } int64 fpow(int64 x,int64 c,int64 M) { int64 res = 1,t = x; while(c) { if(c & 1) res = res * t % M; t = t * t % M; c >>= 1; } return res; } void exgcd(int64 a,int64 b,int64 &x,int64 &y) { if(b == 0) {x = 1;y = 0;} else { exgcd(b,a % b,y,x); y -= a / b * x; } } int64 mul(int64 a,int64 b,int64 M) { int64 res = 0,t = a; while(b) { if(b & 1) res = (res + t) % M; t = (t + t) % M; b >>= 1; } return res; } int64 Calc(int64 a,int64 m) { if(m == 1) return 100; int64 eu = phi(m),g = gcd(eu,m); int64 y = Calc(a,g); int64 a1 = fpow(a,y,m),a2 = y % eu; int64 x,t; exgcd(m,eu,x,t); int64 mod = m * eu / g; x = (x % (eu / g) + eu / g) % (eu / g); x = x * (a2 - a1) / g; x = (x % mod + mod) % mod; x = (mul(x,m,mod) + a1) % mod; while(x < 100) x += mod; return x; } void Solve() { read(A);read(M); int64 x = Calc(A,M); out(x);enter; //if(fpow(A,x,M) == x % M) {puts("YES");} } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif int Q; read(Q); while(Q--) Solve(); }