COCI 2018/2019 CONTEST #2 T4 T5 Solution

abstract

花式暴力

#2 T5 Sunčanje

题意

按顺序给你1e5个长方形(左下角坐标&&长宽),对于每个长方形询问是否有后面的长方形盖住了它。


题解

暴力几何。不需要线段树维护。

用一个排序剪枝,先按矩形的左下角x坐标排序,对于每一个矩形i,枚举后面的所有矩形j,当矩形j的左下角x坐标大于i的右下角x坐标时,break掉。 数据并没有卡


代码

#include <queue>
#include <vector>
#include<map>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm> #define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
using namespace std; int cnt = 0;
const int N = 1e5+1;
inline int read()
{
int X = 0, w = 0; char c = 0;
while (c<'0' || c>'9') { w |= c == '-'; c = getchar(); }
while (c >= '0'&&c <= '9') X = (X << 3) + (X << 1) + (c ^ 48), c = getchar();
return w ? -X : X;
}
int n;
struct rec {
int x, y, len, wid, id;
}a[N];
int ans[N];
int main()
{ n = read();
rep(i, 1, n) {
a[i].x = read(); a[i].y = read(); a[i].len = read(); a[i].wid = read();
//a[i].x += a[i].len;
a[i].id = i;
}
sort(a + 1, a + 1 + n, [](rec a, rec b)->bool {return a.x < b.x; });
rep(i, 1, n) {
int j = i + 1;
while (j<=n && (a[i].x + a[i].len>a[j].x)) {
if (a[j].y >= a[i].y + a[i].wid || a[j].y + a[j].wid <= a[i].y);
else
{
if (a[i].id<a[j].id) ans[a[i].id] = 1;
else ans[a[j].id] = 1;
}
j++;
}
}
rep(i, 1, n)puts(ans[i]?"NE":"DA"); cin >> n;
return 0;
}
//按照x的右下坐标排序,反着剪枝,快了100ms吧
int cnt = 0;
const int N = 1e5+1;
inline int read()
{
int X = 0, w = 0; char c = 0;
while (c<'0' || c>'9') { w |= c == '-'; c = getchar(); }
while (c >= '0'&&c <= '9') X = (X << 3) + (X << 1) + (c ^ 48), c = getchar();
return w ? -X : X;
}
int n;
struct rec {
int x, y, len, wid, id;
}a[N];
int ans[N];
int main()
{ n = read();
rep(i, 1, n) {
a[i].x = read(); a[i].y = read(); a[i].len = read(); a[i].wid = read();
a[i].x += a[i].len;
a[i].id = i;
}
sort(a + 1, a + 1 + n, [](rec a, rec b)->bool {return a.x < b.x; });
rep(i, 2, n) {
int j = i - 1;
while (j >= 1 && (a[i].x - a[i].len<a[j].x)) {
if (a[j].y >= a[i].y + a[i].wid || a[j].y + a[j].wid <= a[i].y);
else
{
if (a[i].id<a[j].id) ans[a[i].id] = 1;
else ans[a[j].id] = 1;
}
j--;
}
}
rep(i, 1, n)puts(ans[i]?"NE":"DA"); //cin >> n;
return 0;
}

心路历程

为什么能暴力啊QAQ ,如果有n个长方形嵌套在一起的,上面程序就是N^N的,必T


T4 Maja

题意

给你一个n*m的矩阵和出发点,你可以上下左右走,最多走k步。你到达任意一点时会获得该点的数值(可重复获得),问最终回到起点的最大收益是多少?


题解

两个结论:

1.路径的前半段和后半段必定是相同的(重复路径)。

证明:若不同,显然取前半段和后半段中较大的重复走两遍,答案显然不会更差。

2.当k很大时,必然是在某两点来回走动。

证明:首先,k较大(k大于n*m)必然是在某个环上绕圈,否则没地方走了。

然后,在某个长度大于2的环上绕圈必然不会比在该环相邻2个之和最大的两个点之间来回走更优。证明:我们把环上的相邻点两两分组,和最大的那组的平均值必然不小于总环的平均值。否则总和小于总和矛盾。

于是我们的路径就是从起点走到某个点,在那个点与相邻的来回走,原路回到起点。

我们可以dp来做,dp[i][j][k]表示第k步走到(i,j)这个点时最大的收益。它可以由dp[i][j][k-1]的上下左右四个点转移而来。

而由于转移第三维只由上一个状态转移而来,所以可以滚动更新。


代码

//用了-inf来代替判边界
# define int long long
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
using namespace std;
const int maxn = 1e2 + 5;
const int INF = 1e18;
int n, m, sr, sc,k;
int c[maxn][maxn];
int f[maxn][maxn][2];
int dir[4][2] = { 1,0, -1,0, 0,1, 0,-1 };
signed main()
{
FAST_IO;
cin >> n >> m >> sr >> sc>>k;
k /= 2;
int ans = -INF;
rep(i, 1, n)rep(j, 1, m) {
cin >> c[i][j];
}
rep(i, 0, n + 1)rep(j, 0, m + 1) { f[i][j][0]= f[i][j][1] = -INF; }
f[sr][sc][0] = 0;
rep(r, 1, min(k, n*m)) {
int now = r & 1;
int pst = !now;
rep(i, 1, n)rep(j, 1, m) {
int tmp = -INF; rep(k, 0, 3) { tmp = max(tmp, f[i + dir[k][0]][j + dir[k][1]][pst]); } f[i][j][now] = max(tmp + c[i][j], -INF);
if (f[i][j][now] < 0) continue;//边界 int dist = f[i][j][now] + tmp;
tmp = 0; rep(k, 0, 3) { tmp = max(tmp, c[i + dir[k][0]][j + dir[k][1]]); } dist += (k - r)*(c[i][j] + tmp);
ans = max(ans, dist);
} }
cout << ans << endl;
cin >> n;
return 0;
}
/*
4 1
1 3
1 4
2 2
1 4
2 3
*/

心路历程



COCI 2018/2019 CONTEST #2 T4 Maja T5Sunčanje Solution的更多相关文章

  1. COCI 2018/2019 CONTEST #2 Solution

    Problem1 Preokret 第一题一定不是什么难题. 第一个问题在读入的时候判断当前时间是不是在1440及以前就行 第二个问题考虑离线处理,由于每个时刻只能最多发生1个事件那么就弄个桶记录每一 ...

  2. 20172328 2018—2019《Java软件结构与数据结构》第二周学习总结

    20172328 2018-2019<Java软件结构与数据结构>第二周学习总结 概述 Generalization 本周学习了第三章集合概述--栈和第四章链式结构--栈.主要讨论了集合以 ...

  3. 2018 - 2019 CTU Open Contest H. Split Game 【SG函数】

    H. Split Game time limit per test 1.0 s memory limit per test 256 MB input standard input output sta ...

  4. 2018 - 2019 CTU Open Contest E. Locker Room 【后缀数组】

    任意门:http://codeforces.com/gym/101954/problem/E E. Locker Room time limit per test 2.0 s memory limit ...

  5. 工具软件集合 Adobe AE PS Pr CC 2018 2019 破解教程

    来源https://mp.weixin.qq.com/s/zeq1sTmaPsKt7Bsok0Ldrg(若链接失效,请关注软件安装管家公众号) 相关链接 Office 2019破解教程 Adobe 2 ...

  6. [USACO 2018 December Contest]作业总结

    t1 Convention 题目大意 每一头牛都有一个来的时间,一共有\(n\)辆车,求出等待时间最长的那头牛等待的最小时间. 解法 第一眼看到这道题还以为是\(2018noip\)普及组的t3魔鬼题 ...

  7. 2018 – 2019 年前端 JavaScript 面试题

    JavaScript 基础问题 1.使以下代码正常运行: JavaScript 代码: const a = [1, 2, 3, 4, 5]; // Implement this a.multiply( ...

  8. Davor COCI 2018

    当题目中有多组解,但要某值最大,该怎么办? 本文为博客园ShyButHandsome的原创作品,转载请注明出处 题目描述 After successfully conquering the South ...

  9. [USACO 2018 Open Contest]作业总结

    t1-Out of Sorts 题目大意 将最大的数冒泡排序到最后需要多少次操作. 分析 排序后判断距离. ac代码 #include<bits/stdc++.h> #define N 1 ...

随机推荐

  1. scheduling while atomic 出现的错误

    产生这种情况的原因: 1.当中断发生时,出现了调度做法, 2.另一个是spin_lock 里调用sleep, 让出调度, 另外线程又进行spin_lock, 导致死锁. 相关问题的链接     1.为 ...

  2. 402 CSS菜鸟:transform and transition

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

  3. 其他-pkuwc2019数学考试题目

    时限150min,有windows和Ubuntu使用 十道填空题,在poj上举行,选手提交答案,系统将答案自动填入一个作用是输出答案的程序,再将该程序提交评测(由于该程序变量名为longlong,所以 ...

  4. Jquyer相册

    点击图片然后弹出相册列表,效果如下: html代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml&q ...

  5. javascript中Math函数的属性与方法

    math函数的属性 Math.PI:返回圆周率. math函数的方法 绝对值: Math.abs(); 对数进行上舍入: Math.ceil(); 对数进行下舍入: Math.floor(); Mat ...

  6. 服务器启动socket服务报错 java.net.BindException:Cannot assign requested address

    错误信息:  2017-06-13 11:18:00,865 [GateServer.java:82][ERROR]:启动服务出错了java.net.BindException: Cannot ass ...

  7. Python学习笔记六

    Python课堂笔记六 常用模块已经可以在单位实际项目中使用,可以实现运维自动化.无需手工备份文件,数据库,拷贝,压缩. 常用模块 time模块 time.time time.localtime ti ...

  8. python 基于机器学习识别验证码

    1.背景    验证码自动识别在模拟登陆上使用的较为广泛,一直有耳闻好多人在使用机器学习来识别验证码,最近因为刚好接触这方面的知识,所以特定研究了一番.发现网上已有很多基于machine learni ...

  9. SpringBoot之hello world!

    哈哈哈,还是在元旦这一天对你下手了.麻溜的给自己充电,在这个寒冬,不断听到裁员的消息或者新闻,可对于我这个外包和外派的人来说,好像并没有受到什么影响.可能是人手不够可能是项目很忙.对于明年的三月金四月 ...

  10. 如何在cocos中为节点添加监听事件

    一般在监听键盘事件时,可是采用以下方式来监听键盘事件: 以及记得定义取消监听的函数(这个摧毁函数会自己调用吗?): 同时这里还有一种传统的监听方式: 但是cocos官方的文档建议我们不要使用这种方式, ...