AtCoder Regular Contest 075 2017年6月4日 C、D、E题解
http://arc075.contest.atcoder.jp/assignments
昨晚做的atcoder,今天写个简单题解。
F题不会做,800point的,就跪了,要等zk大佬来做。zk能做2400的
C题、我看到数据范围就直接100^3的背包,但是如果数据大点还是可以做的,贪心,首先全部值加起来,如果是%10==0的话,就需要去搭错一题,一题最少分的,而且%10 != 0的。
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 1e2 + ;
int dp[maxn * maxn];
void work() {
dp[] = true;
int n;
cin >> n;
for (int i = ; i <= n; ++i) {
int val;
cin >> val;
for (int i = ; i >= val; --i) {
if (dp[i - val]) dp[i] = true;
}
}
int ans = ;
for (int i = ; i >= ; --i) {
if (dp[i]) {
ans = max(ans, i % == ? : i);
}
}
printf("%d\n", ans);
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}
D题、推公式二分,
设x[i]表示在h[i]个位置投放的数量,sum表示x[i]的总和,那么sum就是答案,
对于第h[i]个,需要它死亡,条件是,h[i] - (x[i] * A + (sum - x[i]) * B) <= 0
二分答案sum,然后需要判断n个h[i]都要死亡,每个h[i]死亡,需要的x[i]继续二分,判断即可。sum是满足单调的很容易看出来,
x[i]也满足单调因为A > B,可以化简公式看看,复杂度O(n * log * log),注意不要爆LL
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
LL n, a, b;
LL all;
int hi[ + ];
LL isok(int index, LL sum) {
LL be = , en = sum;
while (be <= en) {
LL mid = (be + en) >> ;
if (a * mid + (sum - mid) * b >= hi[index]) en = mid - ;
else be = mid + ;
}
return be;
}
bool check(LL sum) {
LL need = ;
for (int i = ; i <= n; ++i) {
need += isok(i, sum);
if (need > sum) return false;
}
return true;
}
void work() {
cin >> n >> a >> b;
for (int i = ; i <= n; ++i) {
cin >> hi[i];
all += hi[i];
}
if (n == ) {
cout << (hi[] + a - ) / a << endl;
return;
}
LL be = , en = 1e9;
while (be <= en) {
LL mid = (be + en) >> ;
if (check(mid)) en = mid - ;
else be = mid + ;
}
cout << be << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}
D
E题、化简公式 + BIT
设sum[i]表示前缀和,区间[L, R]满足条件,等价于sum[R] - sum[L - 1] >= (R- L + 1) * k
等价于sum[R] - R * k >= sum[L -1] - (L - 1) * k
相当于找前面有多少个数字比当前数字小,离散化 + bit即可。
复杂度 nlogn
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 2e5 + ;
LL sum[maxn];
int c[maxn];
int n, k;
int lowbit(int x) {
return x & (-x);
}
void upDate(int pos, int val) {
while (pos <= n) {
c[pos] += val;
pos += lowbit(pos);
}
}
int ask(int pos) {
int ans = ;
while (pos) {
ans += c[pos];
pos -= lowbit(pos);
}
return ans;
}
LL vc[maxn], lenvc;
void work() {
scanf("%d%d", &n, &k);
for (int i = ; i <= n; ++i) {
int val;
scanf("%d", &val);
sum[i] = sum[i - ] + val;
}
for (int i = ; i <= n; ++i) {
sum[i] -= 1LL * i * k;
vc[++lenvc] = sum[i];
// cout << sum[i] << " ";
}
// cout << endl;
sort(vc + , vc + + lenvc);
LL ans = ;
for (int i = ; i <= n; ++i) {
int pos = lower_bound(vc + , vc + + lenvc, sum[i]) - vc;
if (sum[i] >= ) {
ans++;
}
ans += ask(pos);
upDate(pos, );
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}
E
AtCoder Regular Contest 075 2017年6月4日 C、D、E题解的更多相关文章
- AtCoder Regular Contest 075
任意门 C - Bugged 题意:类似装箱问题,但是最后体积总和不能为10的倍数. #include<cstdio> #include<cstring> #include&l ...
- AtCoder Regular Contest 075 E - Meaningful Mean(树状数组)
题目大意:求一个数组中,平均值不小于k的连续子序列个数 所有数减去k,算个前缀和出来,就变成二维数点问题了. 没有修改,离线的话就是CZL所说的“NOIP最喜欢的套路”了:倒着加进BIT,以权值为数组 ...
- AtCoder Regular Contest 075 D Widespread
题目传送门 这道题其实二分一下答案就okay了的 不过LL什么的有时候忘了加 被卡了下 #include<cstdio> #include<cstring> #include& ...
- AtCoder Regular Contest 075 C D E (暂时)
C - Bugged 题意 给\(n\)个数,找其中的一个子集,使得其和最大,且不是\(10\)的整数倍. 思路 先对\(n\)个数求和, 如果本身即不被\(10\)整除,则即为答案. 否则,如果本身 ...
- 【arc075f】AtCoder Regular Contest 075 F - Mirrored
题意 给定一个数x,问有多少个正整数y,使得rev(y)-y==x 其中rev(x)表示x按位翻转之后得到的数. x<=1e9 做法 首先通过打表发现,这个答案不会很大. 这就说明解相当地松弛. ...
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Regular Contest 094 (ARC094) CDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...
- AtCoder Regular Contest 092
AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...
- AtCoder Regular Contest 093
AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...
随机推荐
- Linux(Ubuntu16.04)+GitLab8.17deb安装包搭建Git仓库(代码管理系统)
1 下载GitLab安装包 2 执行安装命令 3 验证是否安装和启动成功 4 修改管理员密码 5 其它说明 5.1修改访问URL 5.2修改邮件配置 5.3修改web端口 1下载GitLab安装包 ...
- ACM学习历程—HDU 5289 Assignment(线段树 || RMQ || 单调队列)
Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered fro ...
- 【LeetCode】053. Maximum Subarray
题目: Find the contiguous subarray within an array (containing at least one number) which has the larg ...
- WPF 使用MultiBinding ,TwoWay ,ValidationRule ,需要注意的事项
当wpf使用multibinding时, 其内部的validaterule的value 是其多个Binding的值, 要根据情况去验证, 还有就是在做IMultiConverter的ConvertBa ...
- border-radius实现圆弧阴影效果
1 原理 利用border-radius实现一个圆弧边的矩形,并添加box-shadow,然后放在目标元素的下方 demo: html <div class="demo1"& ...
- 用fpm模式在虚拟主机上安装phpmyadmin
实验环境:CentOS7 1.配置虚拟主机 [root@conf.d localhost]#vi /etc/httpd/conf.d/vhost.conf #配置在/etc/httpd/conf.d下 ...
- ng2中router-outlet用法
说明:router-outlet 是应用中的路由插座,一个页面中可以使用一个或多个router-outlet 1.只使用一个router-outlet 父组件: <router-outlet&g ...
- 数据字典生成工具(生成Excel, Word,PDF,html)
转自:http://www.cnblogs.com/yanweidie/p/3838765.html 数据字典生成工具之旅系列文章导航 数据字典生成工具之旅系列文章导航 宣传语 数据字典生成工具.数据 ...
- [poj3450]Corporate Identity(后缀数组)
题意:多个字符串的最长公共子串. 解题关键:字符串的任何一个子串都是这个字符串的某个后缀的前缀.求A和B的最长公共子串等价于求A的后缀和B的后缀的最长公共前缀的最大值. 后缀数组的经典例题,连接在一起 ...
- sparse matrix format
see Spare Matrix wikipedia item, and scipy's documentation on different choices of sparse matrix typ ...