C - 4/N

列出个方程枚举解一下

#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();
}

D - IntegerotS

每次删掉一个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();
}

E - CARtesian Coodinate

又是几何题。。。

二分次数150WA了改成200过了orz

肯定是这些点的横坐标的中位数和纵坐标的中位数

然后我们用纵坐标距离,二分一个数,画一条平行于x轴的线

然后求出交点,把每条线的交点从小到大排序,每条线能相交且在这个纵坐标值以下的线就是交点横坐标比它小且幅角比它大

树状数组维护一下就行了

#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();
}

F - ModularPowerEquation!!

有点神奇

我们根据欧拉定理,可以有

\(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大于100

#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();
}

【AtCoder】Tenka1 Programmer Contest的更多相关文章

  1. 【AtCoder】Tenka1 Programmer Contest 2019

    Tenka1 Programmer Contest 2019 C - Stones 题面大意:有一个01序列,改变一个位置上的值花费1,问变成没有0在1右边的序列花费最少多少 直接枚举前i个都变成0即 ...

  2. 【AtCoder】Tenka1 Programmer Contest(C - F)

    C - Align 考的时候,我大胆猜了结论,就是一小一大一小一大这么排 证明的话,由于我们总是要加上相邻的最大值而减去最小值,我们就让最大值都保持在前面 如果长度为奇数,要么就是大小大小大,要么是小 ...

  3. 【AtCoder】AISing Programming Contest 2019

    本来以为是1199rated的..仔细一看发现是1999,所以就做了一下 这场涨分很轻松啊...为啥又没打 等pkuwc考完我一定打一场atcoder(咕咕咕,咕咕咕,咕咕咕咕咕咕咕~) 但是其实我思 ...

  4. 【AtCoder】M-SOLUTIONS Programming Contest

    M-SOLUTIONS Programming Contest A - Sum of Interior Angles #include <bits/stdc++.h> #define fi ...

  5. 【AtCoder】Yahoo Programming Contest 2019

    A - Anti-Adjacency K <= (N + 1) / 2 #include <bits/stdc++.h> #define fi first #define se se ...

  6. 【AtCoder】KEYENCE Programming Contest 2019

    A - Beginning 这个年份恐怕需要+2 #include <bits/stdc++.h> #define fi first #define se second #define p ...

  7. 【AtCoder】Dwango Programming Contest V题解

    A - Thumbnail 题意简述:给出N个数,找出N个数中和这N个数平均值绝对值最小的数 根据题意写代码即可= = #include <bits/stdc++.h> #define f ...

  8. Tenka1 Programmer Contest D - Crossing

    链接 Tenka1 Programmer Contest D - Crossing 给定\(n\),要求构造\(k\)个集合\({S_k}\),使得\(1\)到\(n\)中每个元素均在集合中出现两次, ...

  9. Tenka1 Programmer Contest C - Align

    链接 Tenka1 Programmer Contest C - Align 给定一个序列,要求重新排列最大化\(\sum_{i=2}^{i=n} |a_i-a_{i-1}|\),\(n\leq 10 ...

随机推荐

  1. Vue加载json文件

    一.在build/dev-server.js文件里 var app = express() 这句代码后面添加如下(旧版): var appData = require('../address.json ...

  2. VUE2.0 饿了吗视频学习笔记(三):VUE2.0取消了v-link

    https://gitee.com/1981633/vue_study.git 源码下载地址,随笔记动态更新中 写法如下 <div class="tab-item"> ...

  3. I2C和SPI总线对比

    1 iic总线不是全双工,2根线SCL SDA.spi总线实现全双工,4根线SCK CS MOSI MISO 2 iic总线是多主机总线,通过SDA上的地址信息来锁定从设备.spi总线只有一个主设备, ...

  4. MyBatis全局配置文件MyBatis-config.xml代码

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC ...

  5. SNMP收集

    http://velep.com/archives/416.html     协议基本格式

  6. C# http get与post请求方法

    public class HttpTools { public static string GetRequest(string url) { HttpWebRequest request = (Htt ...

  7. 寻路优化(一)——二维地图上A*启发函数的设计探索

    工作中需要优化A*算法,研究了一天,最后取得了不错的效果.看网上的朋友还没有相关的研究,特此记录一下.有错误欢迎大家批评指正.如需转载请注明出处,http://www.cnblogs.com/Leon ...

  8. HDU1233 还是畅通工程【最小生成树】

    题意: 求出连接各个村庄最小的公路总长度,把最小公路总长度求出来. 思路: 最小生成树原理,带入数据求得. 代码: prim: #include<iostream> #include< ...

  9. DropEditText

    https://blog.csdn.net/jdsjlzx/article/details/46860563    https://github.com/qibin0506/DropEditText ...

  10. 深入理解CMA【转】

    转自:https://www.csdn.net/article/a/2016-07-07/15839383 摘要:连续内存分配(简称CMA) 是一种用于申请大量的,并且物理上连续的内存块的方法,在LW ...