【AtCoder】Tenka1 Programmer Contest
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的更多相关文章
- 【AtCoder】Tenka1 Programmer Contest 2019
Tenka1 Programmer Contest 2019 C - Stones 题面大意:有一个01序列,改变一个位置上的值花费1,问变成没有0在1右边的序列花费最少多少 直接枚举前i个都变成0即 ...
- 【AtCoder】Tenka1 Programmer Contest(C - F)
C - Align 考的时候,我大胆猜了结论,就是一小一大一小一大这么排 证明的话,由于我们总是要加上相邻的最大值而减去最小值,我们就让最大值都保持在前面 如果长度为奇数,要么就是大小大小大,要么是小 ...
- 【AtCoder】AISing Programming Contest 2019
本来以为是1199rated的..仔细一看发现是1999,所以就做了一下 这场涨分很轻松啊...为啥又没打 等pkuwc考完我一定打一场atcoder(咕咕咕,咕咕咕,咕咕咕咕咕咕咕~) 但是其实我思 ...
- 【AtCoder】M-SOLUTIONS Programming Contest
M-SOLUTIONS Programming Contest A - Sum of Interior Angles #include <bits/stdc++.h> #define fi ...
- 【AtCoder】Yahoo Programming Contest 2019
A - Anti-Adjacency K <= (N + 1) / 2 #include <bits/stdc++.h> #define fi first #define se se ...
- 【AtCoder】KEYENCE Programming Contest 2019
A - Beginning 这个年份恐怕需要+2 #include <bits/stdc++.h> #define fi first #define se second #define p ...
- 【AtCoder】Dwango Programming Contest V题解
A - Thumbnail 题意简述:给出N个数,找出N个数中和这N个数平均值绝对值最小的数 根据题意写代码即可= = #include <bits/stdc++.h> #define f ...
- Tenka1 Programmer Contest D - Crossing
链接 Tenka1 Programmer Contest D - Crossing 给定\(n\),要求构造\(k\)个集合\({S_k}\),使得\(1\)到\(n\)中每个元素均在集合中出现两次, ...
- Tenka1 Programmer Contest C - Align
链接 Tenka1 Programmer Contest C - Align 给定一个序列,要求重新排列最大化\(\sum_{i=2}^{i=n} |a_i-a_{i-1}|\),\(n\leq 10 ...
随机推荐
- android allowbackup
allowbackup 属性是在application 节点下,作用的设置为true,人们可以通过adb 命令备份一份应用的信息,然后在另外一个设备上,还原这份信息,是一种危险操作,所以,我们一般设为 ...
- Spark2.1.0编译
1.下载spark源码包 http://spark.apache.org/downloads.html 2.安装Scala与maven,解压spark源码包 安装Scala: tar zxf scal ...
- 机器学习:python使用BP神经网络示例
1.简介(只是简单介绍下理论内容帮助理解下面的代码,如果自己写代码实现此理论不够) 1) BP神经网络是一种多层网络算法,其核心是反向传播误差,即: 使用梯度下降法(或其他算法),通过反向传播来不断调 ...
- Linux - rm 修复误删文件
fdisk -l # 分区信息lsblk -f # 查看文件类型/etc/fstab # 查看文件格式挂载启动信息 # debugfs针对 ext2 # ext3grep针对 ext3 # extun ...
- jdk 环境
一.下载 jdk 下载版本为:Linux x64 最新版本 curl -L -O http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u ...
- QWidget窗口类
import sys from PyQt5.QtWidgets import QWidget, QApplication,QPushButton from PyQt5.QtGui import QIc ...
- 计算机网络之互联网|因特网|万维网|HTTP|HTML之间的关系辨析
本博文基于知乎"Web 是什么意思?"一问而引起.(本文均属于博主从知乎上自身所答搬运而至). 如无特殊声明,括号()内以分号分隔的名词均等效. 本文如无特殊引用声明,则所有内容版 ...
- Java中ArrayList循环遍历并删除元素的陷阱
ava中的ArrayList循环遍历并且删除元素时经常不小心掉坑里,昨天又碰到了,感觉有必要单独写篇文章记一下. 先写个测试代码: import java.util.ArrayList; public ...
- EB-GAN系(Energy-based GAN)
学习总结于国立台湾大学 :李宏毅老师 EB-GAN: Energy-based Generative Adversarial Network MA-GAN:MAGAN: Margin Adaptati ...
- IAR KEIL ECLIPSE使用JlinkScript文件进行调试
转载自:https://wiki.segger.com/Using_J-Link_Script_Files Using J-Link Script Files Contents [hide] ...