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-的应该都能有一定的思路? 记不清了 但总之是要智力康复一下 又加上文化课比较紧 所以这个大概就会是长期计划了 ————————————分鸽线 ...
随机推荐
- java 选择结构if
图1-1 if…else if…else语句的流程图 选择结构if语句与三元运算转换 三元运算符,它和if-else语句类似,语法如下: 判断条件 ? 表达式1 : 表达式2 三元运算符会得 ...
- Spring Boot 成长之路(一) 快速上手
1.创建工程 利用IntelliJ IDEA新建一个Spring Boot项目的Web工程 2.查看初始化的spring boot项目 工程建好之后会出现如下的目录结构: 值得注意的第一件事是,整个项 ...
- tomcat下文件路径
第一种:复制要访问的文件a.txt至tomcat安装路径下的webapps/ROOT文件夹下: 访问路径为:localhost:8080/a.txt 或者在webapps文件夹下新建一个文件夹(tes ...
- H5页面在手机上查看 使用手机浏览自己的web项目
参考:http://www.browsersync.cn/#install 首先全局安装BrowserSync : npm install -g browser-sync 其次在项目文件夹下运行: b ...
- spring源码读书笔记
如果我们在web项目里面使用spring的话,通常会在web.xml里面配置一个listener. <listener> <listener-class> org.spring ...
- day 73 Django基础八之cookie和session
Django基础八之cookie和session 本节目录 一 会话跟踪 二 cookie 三 django中操作cookie 四 session 五 django中操作session 六 x ...
- Print Article /// 斜率优化DP oj26302
题目大意: 经典题 数学分析 G(a,b)<sum[i]时 a优于b G(a,b)<G(b,c)<sum[i]时 b必不为最优 #include <bits/stdc++.h& ...
- WPF drag过程中显示ToolTip.
原文:WPF drag过程中显示ToolTip. 在drag/drop过程中,我们在判断出over的元素上是否可以接受drag的东西之后,通常是通过鼠标的样式简单告诉用户这个元素不接受现在drag的内 ...
- java_IO流(输出流)
** * io流: * 输入流:硬盘输入到内存 字节/字符输入流 * 输出流:内存输出到硬盘 字节/字符输入流 * 字节流:一切数据都是字节存储(二进制) * 字节输出流(OutputStream): ...
- MATLAB 中自定义函数的使用
MATLAB在文件内部(在函数内部)定义函数,但文件名以开头函数来命名,与Java中每个文件只能有一个公开类,但在文件内部还是可以定义其他非公开类一个道理. 无参函数 do.m function do ...