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的更多相关文章

  1. 【AtCoder】AGC034

    AGC034 刷了那么久AtCoder我发现自己还是只会ABCE(手动再见 A - Kenken Race 大意是一个横列,每个点可以跳一步或者跳两步,每个格子是空地或者石头,要求每一步不能走到石头或 ...

  2. AtCoder整理(持续更新中……)

    做了那么久的atcoder觉得自己的题解发的很乱 给有想和我一起交流atcoder题目(或者指出我做法的很菜)(或者指责我为什么整场比赛只会抄题解)的同学一个索引的机会??? 于是写了个爬虫爬了下 A ...

  3. 【长期计划】Atcoder题目泛做

    之前学长跟我说的是700-的应该都能自己做? 然后1000-的应该都能有一定的思路? 记不清了 但总之是要智力康复一下 又加上文化课比较紧 所以这个大概就会是长期计划了 ————————————分鸽线 ...

随机推荐

  1. HTML学习笔记 表单元素

    <form></form>代表表单 action:往什么地方提交 method:提交方式  get显示提交(不安全)  post隐视提交(安全) 提交内容:  name=输入的 ...

  2. python实现百度OCR图片识别

    一.直接上代码 import base64 import requests class CodeDemo: def __init__(self,AK,SK,code_url,img_path): se ...

  3. Oracle Spatial导入shp数据

    现在开始尝试用oracle spatial管理空间数据,刚学会shp数据的导入,总结如下.oracle11g安装后,已经有了oracle spatial组件,我们只需要用shp2sdo.exe工具,就 ...

  4. selenium python bindings 初步用法及简单参考例子

    掌握selenium最简单的方法就是参考例子进行学习,下面给出之前项目的测试例子及分析 # -*- coding: utf-8 -*- import time from selenium import ...

  5. (3)mysql表和字段的操作

    创建表 create table name( id int, student ) ); 查看表结构 ****常用**** describe 表名; 修改表名 老表 rename 新表 ALTER TA ...

  6. Mysql配置innodb_flush_log_at_trx_commit

    当innodb_flush_log_at_trx_commit被 设置为0,日志缓冲每秒一次地被写到日志文件,并且对日志文件做到磁盘操作的刷新,但是在一个事务提交不做任何操作.当这个值为1(默认值)之 ...

  7. 第八篇:ZTree操作总结

    花了一个多星期,终于完成了这个完整的功能,今天周五是时候总结下加深理解了. 项目要实现的功能:将树形目录发布到发布库,若是根目录,没有发布,连同自己和下面所有的子目录们全部发布:不是根目录,判断父目录 ...

  8. Hive学习笔记简版

    一.概述 1. Hive是Apache提供的基于Hadoop的数据仓库管理工具2. Hive提供了类SQL语言来操作Hadoop,底层会将SQL转化为MapReduce来执行,所以效率会比较低3. H ...

  9. 程序员如何面对 HR 面试的 40 个问题!

    讲一个身边朋友亲身经历的故事吧. 一个技术非常牛的朋友去阿里面试,成功通过了几轮技术车轮战,最后躺在了 HR 面上...所以,尽管你技术再牛逼,你回答不好 HR 的问题,赢得不了 HR 的认可,你最终 ...

  10. python pywin32学习笔记

    参考博客链接 https://blog.csdn.net/polyhedronx/article/details/81988948 参考博客链接 https://www.cnblogs.com/zha ...