agc034
A:题意:你有一个1 * n的网格,有些地方是障碍。你有两个人,分别要从a到b和从c到d,一次只能向右跳1步或者两步。求是否可行。
解:先判断有没有2个连续的障碍,然后判断是否能错车。
#include <bits/stdc++.h>
const int N = ;
char str[N];
int main() {
int n, a, b, c, d;
scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
scanf("%s", str + );
if(c < d) {
for(int i = a; i < d; i++) {
if(str[i] == '#' && str[i + ] == '#') {
printf("No\n");
return ;
}
}
printf("Yes\n");
return ;
}
else {
for(int i = a; i < c; i++) {
if(str[i] == '#' && str[i + ] == '#') {
printf("No\n");
return ;
}
}
for(int i = b; i <= d; i++) {
if(str[i - ] == '.' && str[i] == '.' && str[i + ] == '.') {
printf("Yes\n");
return ;
}
}
printf("No\n");
return ;
}
return ;
}
AC代码
B:题意:你有一个ABC字符串,你能进行的操作就是把某个ABC变成BCA。求最多进行多少次操作。
解:发现可以把BC看做一个整体。单独的B和C看做障碍物。
那么对于每一段无障碍物的连续A,BC,求逆序对就好了。
#include <bits/stdc++.h> typedef long long LL;
const int N = ; char str[N];
bool vis[N]; int main() { scanf("%s", str + );
int n = strlen(str + );
for(int i = ; i <= n; i++) {
if(str[i] == 'C' && str[i - ] != 'B') {
vis[i] = ;
}
if(str[i] == 'B' && str[i + ] != 'C') {
vis[i] = ;
}
}
LL ans = ;
for(int l = , r; l <= n; l = r + ) {
while(vis[l]) {
++l;
}
if(l > n) break;
r = l;
while(!vis[r + ] && r < n) {
++r;
}
LL cnt = , t = ;
for(int i = l; i <= r; i++) {
if(str[i] == 'A') {
++cnt;
}
else if(str[i] == 'B' && str[i + ] == 'C') {
++i;
t += cnt;
}
}
ans += t;
}
printf("%lld\n", ans);
return ;
}
AC代码
C:题意:你有n场考试,满分X分。你的对手每场考试得了bi分。你每学习一个小时就能把某场考试提高1分。你能给每场考试选择一个li~ri之间的加权。求你最少花多少小时才能不比对手考的低。
解:发现加权要么是li要么是ri。且你比对手高就是ri,否则就是li。
然后发现如果有两场考试都没有满分,最优策略是把一场考试的分挪到另一场上。
然后就发现答案一定是若干场满分和一场非满分。这时候就可以排序了,然后二分答案,枚举非满分是哪一场。
#include <bits/stdc++.h> typedef long long LL;
const int N = ; struct Node {
LL l, r, b, h;
inline bool operator < (const Node &w) const {
return h > w.h;
}
}node[N]; LL X, D, sum[N];
int n; inline LL cal(LL a, LL i) {
if(a <= node[i].b) {
return a * node[i].l;
}
return node[i].b * node[i].l + (a - node[i].b) * node[i].r;
} inline bool check(LL k) {
LL ans = , r = k % X, t = k / X;
if(t >= n) {
return sum[n];
}
// printf("r = %lld t = %lld \n", r, t);
for(int i = ; i <= n; i++) {
if(i <= t) ans = std::max(ans, cal(r, i) + sum[t + ] - node[i].h);
else {
ans = std::max(ans, cal(r, i) + sum[t]);
}
}
//printf("k = %lld ans = %lld D = %lld \n", k, ans, D);
return ans >= D;
} int main() { scanf("%d%lld", &n, &X);
for(int i = ; i <= n; i++) {
scanf("%lld%lld%lld", &node[i].b, &node[i].l, &node[i].r);
node[i].h = node[i].b * node[i].l + (X - node[i].b) * node[i].r;
D += node[i].b * node[i].l;
}
std::sort(node + , node + n + );
for(int i = ; i <= n; i++) {
sum[i] = sum[i - ] + node[i].h;
}
LL l = , r = 4e18;
while(l < r) {
LL mid = (l + r) >> ;
if(check(mid)) {
r = mid;
}
else {
l = mid + ;
}
}
printf("%lld\n", r);
return ;
}
AC代码
D:题意:给你平面上两组n个点,你要把它们配对,使得曼哈顿距离最大。n <= 1000。
解:曼哈顿距离有2个绝对值,拆开就是4种情况。直接建4个中转点表示这4种情况,跑最大费用最大流。
#include <bits/stdc++.h> #define int LL typedef long long LL;
const int N = , INF = 0x3f3f3f3f3f3f3f3fll; struct Edge {
int nex, v, c, len;
Edge(){}
Edge(int N, int V, int C, int L) {
nex = N, v = V, c = C, len = L;
}
}edge[]; int tp = ; int e[N], n, tot, d[N], pre[N], flow[N], Time, vis[N];
std::queue<int> Q; inline void add(int x, int y, int z, int w) {
edge[++tp] = Edge(e[x], y, z, w);
e[x] = tp;
edge[++tp] = Edge(e[y], x, , -w);
e[y] = tp;
return;
} inline bool SPFA(int s, int t) {
memset(d, 0x3f, sizeof(d));
Q.push(s);
++Time;
d[s] = ;
vis[s] = Time;
flow[s] = INF;
while(Q.size()) {
int x = Q.front();
Q.pop();
vis[x] = ;
for(int i = e[x]; i; i = edge[i].nex) {
int y = edge[i].v;
if(edge[i].c && d[y] > d[x] + edge[i].len) {
d[y] = d[x] + edge[i].len;
pre[y] = i;
flow[y] = std::min(flow[x], edge[i].c);
if(vis[y] != Time) {
vis[y] = Time;
Q.push(y);
}
}
}
}
return d[t] < INF;
} inline void update(int s, int t) {
int f = flow[t];
while(s != t) {
int i = pre[t];
edge[i].c -= f;
edge[i ^ ].c += f;
t = edge[i ^ ].v;
}
return;
} inline int solve(int s, int t, int &cost) {
cost = ;
int ans = ;
while(SPFA(s, t)) {
//printf("!");
ans += flow[t];
cost += flow[t] * d[t];
update(s, t);
}
return ans;
} signed main() { scanf("%lld", &n);
int s = * n + , t = s + , x, y, z;
for(int i = ; i <= n; i++) {
scanf("%lld%lld%lld", &x, &y, &z);
add(s, i, z, );
add(i, * n + , z, x + y);
add(i, * n + , z, y - x);
add(i, * n + , z, x - y);
add(i, * n + , z, -x - y);
}
for(int i = ; i <= n; i++) {
scanf("%lld%lld%lld", &x, &y, &z);
add(n + i, t, z, );
add( * n + , n + i, z, -x - y);
add( * n + , n + i, z, x - y);
add( * n + , n + i, z, y - x);
add( * n + , n + i, z, x + y);
}
//puts("OVER");
int cost = ;
solve(s, t, cost);
printf("%lld\n", -cost);
return ;
}
AC代码
agc034的更多相关文章
- 【AtCoder】AGC034
AGC034 刷了那么久AtCoder我发现自己还是只会ABCE(手动再见 A - Kenken Race 大意是一个横列,每个点可以跳一步或者跳两步,每个格子是空地或者石头,要求每一步不能走到石头或 ...
- AtCoder整理(持续更新中……)
做了那么久的atcoder觉得自己的题解发的很乱 给有想和我一起交流atcoder题目(或者指出我做法的很菜)(或者指责我为什么整场比赛只会抄题解)的同学一个索引的机会??? 于是写了个爬虫爬了下 A ...
- 【长期计划】Atcoder题目泛做
之前学长跟我说的是700-的应该都能自己做? 然后1000-的应该都能有一定的思路? 记不清了 但总之是要智力康复一下 又加上文化课比较紧 所以这个大概就会是长期计划了 ————————————分鸽线 ...
随机推荐
- [JZOJ6278] 2019.8.5【NOIP提高组A】跳房子
题目 题目大意 给你一个矩阵,从\((1,1)\)开始,每次往右上.右.右下三个格子中权值最大的那个跳. 第一行上面是第\(n\)行,第\(m\)列右边是第\(1\)列.反之同理. 有两个操作:跳\( ...
- UVA-307-Sticks-dfs+剪枝
George took sticks of the same length and cut them randomly until all parts became at most 50 units ...
- ELK5.2+kafka+zookeeper+filebeat集群部署
架构图 考虑到日志系统的可扩展性以及目前的资源(部分功能复用),整个ELK架构如下: 架构解读 : (整个架构从左到右,总共分为5层) 第一层.数据采集层 最左边的是业务服务器集群,上面安装了file ...
- day 72 Django基础七之Ajax
Django基础七之Ajax 本节目录 一 Ajax简介 二 Ajax使用 三 Ajax请求设置csrf_token 四 关于json 五 补充一个SweetAlert插件(了解) 六 同源策略与 ...
- day 49 Bootstrap框架和inconfont、font-awesome使用
Bootstrap框架和inconfont.font-awesome使用 iconfont的使用:https://www.cnblogs.com/clschao/articles/10387580 ...
- 国外主机如何ICP备案
想都不要想了,无法备案. 因为,备案是在主机服务器提供商处的备案平台提交申请,国外的主机服务商是没有这种平台服务的.(跟你域名在哪儿买的没关系) 下面,把昨天折腾到半夜的过程记录一下,希望可以帮到需要 ...
- k8s常用的资源
1. 创建pod资源 pod是最小的资源单位 任何一个k8s资源都可以有yml清单文件来定义 k8s yaml的主要组成 apiVersion: v1 api版本 kind: pod 资源类型 met ...
- 面试系列17 redis cluster
1.redis cluster介绍 redis cluster (1)自动将数据进行分片,每个master上放一部分数据(2)提供内置的高可用支持,部分master不可用时,还是可以继续工作的 在re ...
- python 请求测试环境的https接口地址报SSL错误验证,访问不了
解决文案: response = requests.post(url, data=payload, json=None, headers=headers,verify=False)print(resp ...
- 以太坊solidity智能合约语言学习资源整理
暂时看到篇文章写的不错,先收集下来,后面有机会自己也整理一个 Solidity语言学习(一)Solidity语言学习(二)——Solidity的安装与编译Solidity语言学习(三)——智能合约编程 ...