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 ...
随机推荐
- LeetCode前100题(EASY难度)
1 Two Sum Given an array of integers, return indices of the two numbers such that they add up to a s ...
- Django组件-分页器
Django的分页器(paginator) view from django.shortcuts import render,HttpResponse # Create your views here ...
- ES--06
第51.初识搜索引擎_上机动手实战多搜索条件组合查询 课程大纲 GET /website/article/_search{ "query": { "bool": ...
- vue-cli 3.0
安装 vue-cli 3.0 时报错 vue-cli3安装遇到的问题,卸载不掉旧版本,导致更新不了 vue-cli 2.9.6 版本卸载不了 作者:Runner_leaf链接:https://www. ...
- uni-app调用原生的文件系统管理器(可选取附件上传)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- ssm实现图片上传
在使用ssm完成前后端对接时,总免不了前台传过来的文件问题,而html中的<input>框直接使用时,往往会获取不到路径,今天在完成图片上传后的来做个总结 首先,前台页面 <!DOC ...
- 金蝶K/3 跟踪语句_业务单据
跟踪语句_业务单据_BOM select * from t_TableDescription where Ftablename like '%ICBOM%' order by FFieldName o ...
- js属性对象的hasOwnProperty方法
Object的hasOwnProperty()方法返回一个布尔值,判断对象是否包含特定的自身(非继承)属性. 判断自身属性是否存在 var o = new Object(); o.prop = 'ex ...
- SQL反模式学习笔记14 关于Null值的使用
目标:辨别并使用Null值 反模式:将Null值作为普通的值,反之亦然 1.在表达式中使用Null: Null值与空字符串是不一样的,Null值参与任何的加.减.乘.除等其他运算,结果都是Null: ...
- PSO:利用PSO实现对一元函数y = sin(10*pi*x) ./ x进行求解优化,找到最优个体适应度—Jason niu
x = 1:0.01:2; y = sin(10*pi*x) ./ x; figure plot(x, y) title('绘制目标函数曲线图—Jason niu'); hold on c1 = 1. ...