COCI 2018/2019 CONTEST #2 T4 Maja T5Sunčanje Solution
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的更多相关文章
- COCI 2018/2019 CONTEST #2 Solution
Problem1 Preokret 第一题一定不是什么难题. 第一个问题在读入的时候判断当前时间是不是在1440及以前就行 第二个问题考虑离线处理,由于每个时刻只能最多发生1个事件那么就弄个桶记录每一 ...
- 20172328 2018—2019《Java软件结构与数据结构》第二周学习总结
20172328 2018-2019<Java软件结构与数据结构>第二周学习总结 概述 Generalization 本周学习了第三章集合概述--栈和第四章链式结构--栈.主要讨论了集合以 ...
- 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 ...
- 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 ...
- 工具软件集合 Adobe AE PS Pr CC 2018 2019 破解教程
来源https://mp.weixin.qq.com/s/zeq1sTmaPsKt7Bsok0Ldrg(若链接失效,请关注软件安装管家公众号) 相关链接 Office 2019破解教程 Adobe 2 ...
- [USACO 2018 December Contest]作业总结
t1 Convention 题目大意 每一头牛都有一个来的时间,一共有\(n\)辆车,求出等待时间最长的那头牛等待的最小时间. 解法 第一眼看到这道题还以为是\(2018noip\)普及组的t3魔鬼题 ...
- 2018 – 2019 年前端 JavaScript 面试题
JavaScript 基础问题 1.使以下代码正常运行: JavaScript 代码: const a = [1, 2, 3, 4, 5]; // Implement this a.multiply( ...
- Davor COCI 2018
当题目中有多组解,但要某值最大,该怎么办? 本文为博客园ShyButHandsome的原创作品,转载请注明出处 题目描述 After successfully conquering the South ...
- [USACO 2018 Open Contest]作业总结
t1-Out of Sorts 题目大意 将最大的数冒泡排序到最后需要多少次操作. 分析 排序后判断距离. ac代码 #include<bits/stdc++.h> #define N 1 ...
随机推荐
- webpack学习记录 二
开发网站 用polyfill(全局污染) 开发框架 用Runtime(局部污染) 在.babelrc文件中
- C# - 代码重构
隐藏更多 只暴露集合中供人使用的单一功能,将关于集合的更多功能隐藏掉. 旧版本 public class Animal{ private List<string> LanguageL ...
- 设计模式八: 委派(Delegate)
简介 委派模式不属于GOF23种设计模式, 主要角色有三种: 抽象任务角色, 委派者角色, 具体任务角色. 实现层面上, 定义一个抽象接口, 它有若干实现类, 他们真正执行业务方法, 这些子类是具体任 ...
- torch画散点图
import torch from torch.autograd import Variable import torch.nn.functional as F import matplotlib.p ...
- Web从入门到放弃<6>
<1> Canvas. 1,灰度图: js: function showAsGray() { var imgNode = document.getElementById('img'); ...
- 使用pytesseract出现的问题
dyld: Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.8.dylib Referenced from: /usr/local/lib/li ...
- tarjan 题目汇总(含解析)
下面容许我偷个懒,洛谷上写过的blog我就不来再抄一遍了 洛谷P3436 [[POI2006]PRO-Professor Szu](别称:作死的老教授) 洛谷P4306 [[JSOI2010]连通数] ...
- selenium——find_element_by_xx 与 find_element(By.XX,'XXXX')
- MVC中一般为什么用IQueryable而不是用IList?
IList(IList<T>)会立即在内存里创建持久数据,这就没有实现“延期执行(deferred execution)”,如果被加载的实体有关联实体(associations),此关联实 ...
- Python 爬虫 58同城
目标站点需求分析 获取各类产品的名字,地区,时间,价格 涉及的库 BeautifulSoup,requests,time,pymongo 获取各大类产品的链接 获取单页源码 解析单页源码 保存到文件中 ...