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. 选择器zuoye

    代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title ...

  2. SpringMVC的孪生兄弟WebFlux

    一.入门文字介绍 官方口水话简短翻译: Spring WebFlux是一个非阻塞的Web框架,用于利用多核,短时间可一处理大量并发连接. 非阻塞式 在servlet3.1提供了非阻塞的API,WebF ...

  3. VC++ COMBO BOX控件的使用

    1.你在编辑状态下点那个控件的向下的三角形,就出冒出来一个可以调高度的东东.将高度调高,否则在执行时会不能显示下拉选项.   2.为combo box添加选项,在编辑状态下选combo box控件的属 ...

  4. pca算法实现

    pca基础知识不了解的可以先看下一这篇博客:https://www.cnblogs.com/lliuye/p/9156763.html 具体算法实现如下: import numpy as np imp ...

  5. Heartbeat基本介绍----HA / vmware HA FT

    Heartbeat是High-Availability Linux Project (Linux下的高可用性项目)的产物,是一套提供防止业务主机因不可避免的意外性或计划性宕机问题的高可用性软件.Hea ...

  6. P1934 封印

    P1934 封印 题目描述 很久以前,魔界大旱,水井全部干涸,温度也越来越高.为了拯救居民,夜叉族国王龙溟希望能打破神魔之井,进入人界“窃取”水灵珠,以修复大地水脉.可是六界之间皆有封印,神魔之井的封 ...

  7. 没有找到mfc100.dll

    转自VC错误:http://www.vcerror.com/?p=86 问题描述: 生成的exe文件在编译的时候会提示"没有找到mfc100.dll",这个时候需要更改配置为静态编 ...

  8. TStringList常用操作

    TStringList常用操作 //TStringList 常用方法与属性: var List: TStringList; i: Integer; begin List := TStringList. ...

  9. python 集合(set)

    1.集合的创建 集合是一个无序不重复元素的集.基本功能包括关系测试和消除重复元素. 创建集合:大括号或 set() 函数可以用来创建集合.注意:想要创建空集合,你必须使用 set() 而不是 {},后 ...

  10. Mybatis功能架构及执行流程

    原文地址:http://blog.51cto.com/12222886/2052647 一.功能架构设计 功能架构讲解: 我们把Mybatis的功能架构分为三层: (1) API接口层:提供给外部使用 ...