Atcoder CADDi 2018 Solution
C - Product and GCD
Solved.
题意:
给出$n个数$的乘积,求$这n个数$的最大的可能是GCD
思路:
分解质因子,那么$每个质因子的贡献就是其质因子个数/ n的乘积$
#include <bits/stdc++.h>
using namespace std; #define ll long long
ll n, p; int main()
{
while (scanf("%lld%lld", &n, &p) != EOF)
{
if (n == )
{
printf("%lld\n", p);
continue;
}
ll res = ;
for (ll i = ; i * i <= p; ++i)
{
ll tmp = ;
while (p % i == )
{
++tmp;
p /= i;
}
while (tmp >= n)
{
tmp -= n;
res *= i;
}
}
printf("%lld\n", res);
}
return ;
}
D - Harlequin
Solved.
题意:
有$n种颜色的苹果,每种颜色有a_i个,每次可以选择若干个不同颜色的苹果拿掉,轮流拿,谁不能拿谁输$
问 先手胜还是后手胜
思路:
必败局面是当前场上所有颜色的苹果都是偶数个,这样的话,你拿什么,对方跟着你拿,对方肯定胜利
那么必胜局面就是当前场上存在有若干种奇数个颜色的苹果,取掉这些苹果,转换成必败局面留给对方就好了
简单判一判就没了
#include <bits/stdc++.h>
using namespace std; int n, x; int main()
{
while (scanf("%d", &n) != EOF)
{
x = ;
for (int i = , y; i <= n; ++i)
{
scanf("%d", &y);
x += y & ;
}
puts(x ? "first" : "second");
}
return ;
}
E - Negative Doubling
Upsolved.
题意:
给出n个数,对每个数的操作只有 $\cdot -2$ ,求最少多少次操作使得序列变成非下降序列
思路:
我们考虑序列中如果存在正数和负数,那么必然存在一个界限,左边全是负数,右边全是正数
那么我们可以预处理出
$f[i] 表示 使得从i开始是一个非下降序列的最小花费$
$g[i]表示 i以及i以前是一个非下降序列,且全都是负数的最小花费$
维护的过程可以用一个队列
刚开始以为如果当前数比之前的数不满足大小关系,后面的数或者前面的数全都要动
但实际上并不是这样,
比如说
5 3 4 1000000
推到5的时候 只有 3 和 4 要改变
#include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 200010
#define pii pair <int, int>
int n;
ll a[N], b[N], f[N], g[N], lazy; void Run()
{
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; ++i) scanf("%lld", a + i);
queue <pii> q;
f[n] = ;
for (int i = n - ; i >= ; --i)
{
f[i] = f[i + ];
if (a[i] > a[i + ])
{
ll tmp = a[i + ];
int cnt = ;
while (tmp < a[i])
{
tmp *= ;
cnt += ;
}
int x = i;
while (!q.empty())
{
f[i] += 1ll * (q.front().second - x) * cnt;
if (q.front().first <= cnt) cnt -= q.front().first;
else
{
pii tmpp = q.front();
tmpp.first -= cnt;
cnt = ;
q.pop();
q.push(tmpp);
break;
}
x = q.front().second;
q.pop();
}
f[i] += 1ll * (n - x) * cnt;
}
else
{
ll tmp = a[i];
int cnt = ;
while (tmp * <= a[i + ])
{
tmp *= ;
cnt += ;
}
if (cnt) q.push(pii(cnt, i));
}
}
while (!q.empty()) q.pop();
g[] = ;
b[] = -a[];
for (int i = ; i <= n; ++i)
{
g[i] = g[i - ] + ;
b[i] = -a[i];
if (b[i] < b[i - ])
{
ll tmp = b[i - ];
int cnt = ;
while (tmp > b[i])
{
tmp *= ;
cnt += ;
}
int x = i;
while (!q.empty())
{
g[i] += 1ll * (x - q.front().second) * cnt;
if (q.front().first <= cnt) cnt -= q.front().first;
else
{
pii tmpp = q.front();
q.pop();
tmpp.first -= cnt;
cnt = ;
q.push(tmpp);
break;
}
x = q.front().second;
q.pop();
}
g[i] += 1ll * (x - ) * cnt;
}
else
{
ll tmp = b[i];
int cnt = ;
while (tmp * >= b[i - ])
{
tmp *= ;
cnt += ;
}
if (cnt) q.push(pii(cnt, i));
}
}
ll res = min(f[], g[n]);
for (int i = ; i < n; ++i) res = min(res, g[i] + f[i + ]);
printf("%lld\n", res);
}
} int main()
{
#ifdef LOCAL
freopen("Test.in", "r", stdin);
#endif Run();
return ;
}
Atcoder CADDi 2018 Solution的更多相关文章
- 【AtCoder】CADDi 2018
C - Product and GCD 题解 直接分解质因数,然后gcd每次多一个质因数均摊到每个\(N\)上的个数 代码 #include <bits/stdc++.h> #define ...
- ACM ICPC, Amman Collegiate Programming Contest (2018) Solution
Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路 ...
- Good Bye 2018 Solution
A. New Year and the Christmas Ornament 签到. #include <bits/stdc++.h> using namespace std; int a ...
- Avito Cool Challenge 2018 Solution
A. Definite Game 签. #include <bits/stdc++.h> using namespace std; int main() { int a; while (s ...
- ACM ICPC, JUST Collegiate Programming Contest (2018) Solution
A:Zero Array 题意:两种操作, 1 p v 将第p个位置的值改成v 2 查询最少的操作数使得所有数都变为0 操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...
- ACM ICPC, Damascus University Collegiate Programming Contest(2018) Solution
A:Martadella Stikes Again 水. #include <bits/stdc++.h> using namespace std; #define ll long lon ...
- ZOJ Monthly, March 2018 Solution
A - Easy Number Game 水. #include <bits/stdc++.h> using namespace std; #define ll long long #de ...
- ZOJ Monthly, January 2018 Solution
A - Candy Game 水. #include <bits/stdc++.h> using namespace std; #define N 1010 int t, n; int a ...
- ZOJ Monthly, June 2018 Solution
A - Peer Review Water. #include <bits/stdc++.h> using namespace std; int t, n; int main() { sc ...
随机推荐
- HDFS原理解析(总体架构,读写操作流程)
前言 HDFS 是一个能够面向大规模数据使用的,可进行扩展的文件存储与传递系统.是一种允许文件通过网络在多台主机上分享的文件系统,可让多机器上的多用户分享文件和 存储空间.让实际上是通过网络来访问文件 ...
- 查看进程动态:top
top命令用于查看进程动态,即进程使用系统资源的情况,常见用法如下: [root@localhost ~]$ top # 动态查看进程使用资源的情况,每三秒刷新一次 [root@localhost ~ ...
- apache MINA之心跳协议运用
摘要 心跳协议,对基于CS模式的系统开发来说是一种比较常见与有效的连接检测方式,最近在用MINA框架,原本自己写了一个心跳协议实现,后来突然发现MINA本身带有这样一个心跳实现,感于对框架的小小崇拜, ...
- intellij idea 2018注册码|intellij idea 2018破解文件下载(附破解教程/汉化包)
intellij idea 2018破解文件http://www.3322.cc/soft/37661.html intellij idea 2018注册码是一款针对“intellij idea 20 ...
- (转)关于android设备管理器的一些分析
转自http://bbs.pediy.com/showthread.php?t=183692 想必很多人都知道轰动一时android木马OBAD,该木马利用android设备管理器的漏洞,当用户激活设 ...
- win7(64)使用vim碰到的奇怪问题
一直使用conemu做控制台使用vim,操作系统win7 64位,一直用的很好. 今天使用gvim打开文件发现c:\program file(x86)\vim\_vimrc不生效,最奇怪的是,采用控制 ...
- VIM 多行注释与取消
注释: 在使用vim的过程中, 注释是一个比较烦人的事情,要一行一行注释,或者用/* */来注释 下面这种方法可以快捷的进行多行注释. 1.进入vi/vim编辑器,按CTRL+V进入可视化模式(VIS ...
- webpack中,require的五种用法
a.js: module.exports = function(x){ console.log(x); } 一,commonjs同步: var b = require('./a');b('你好')// ...
- 【BZOJ4764】弹飞大爷 LCT
[BZOJ4764]弹飞大爷 Description 自从WC退役以来,大爷是越来越懒惰了.为了帮助他活动筋骨,也是受到了弹飞绵羊一题的启发,机房的小伙伴们决定齐心合力构造一个下面这样的序列.这个序列 ...
- 微信小程序 --- 完成小程序支付功能
最近开发小程序,一直在看小程序的支付.经过一天的努力,小程序支付功能最终实现了. 下面感谢 csdn 博主:千堆雪惹尘埃 发布的 " 小程序与php 实现微信支付 " 原文地址: ...