当前位置:网站首页>[noi simulation] Elis (greedy, simulation)
[noi simulation] Elis (greedy, simulation)
2022-07-02 14:59:00 【DD(XYX)】
Topic
1 s 512 m b _{_{\rm1\,s~~~~~512\,mb}} 1s 512mb



Answer key
We will find that , At any time, the minimum threshold of the magic eye is one of the four corners of the square , Therefore, we only need to consider the magic eyes on the four corners .
It can be greedy to judge whether there is a solution .
Get the scheme with the smallest dictionary order , Try to go right every step + Greedy judge whether there is a solution .
So how to judge greedily ?
notes : The following is the greedy strategy to judge whether there is a solution , Not the final output answer .
We can partition the whole grid first : The five pointed star array is the magic eye area 
Because the threshold value of magic eye decreases every time is equal to Manhattan distance , Therefore, the general direction must be the closer to the magic eye area, the better .
stay A Regional time , Greedily walked all the way to the lower left corner of the magic eye area , Feel free to go halfway , The effect on the magic eye area is the same .
In the blue arrow area , The closer you get, the better , It must be mindless to go up .
stay B Regional time , It doesn't matter how you go , The effect on the magic eye area is the same .
When you enter the magic eye area , It's going to be a bit of a hassle ,
Suppose you are currently in the magic eye area ( x , y ) (x,y) (x,y) , Walking out of the magic eye area halfway is definitely not good , So it must be all the way to C C C spot , This is the right way A , C A,C A,C The impact is the same . It's out C C C After o'clock, I just walk around , So we should try to make B , D B,D B,D The minimum value of the threshold is the maximum .
The plan on the left is right B B B The most beneficial 、 Yes D D D The most harmful plan , The plan on the right is the opposite :
We consider the adjustment method , Adjust from the scheme on the left to the scheme on the right , One at a time “ Up right ” become “ The upper right ”, Will just let B B B The threshold of 2, D D D The threshold of is increased 2 . therefore , No matter what plan , Yes B , D B,D B,D The threshold contribution and are equal , The boundary is the above two cases . We can O ( 1 ) O(1) O(1) Greedy distribution , In the end B , D B,D B,D The threshold of is as average as possible .
Code implementation is a simulation problem .
Time complexity O ( n ) O(n) O(n) . Since it's a simulation , Constants can be written big .
CODE
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<random>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#pragma GCC optimize(2)
using namespace std;
#define MAXN (1<<16|5)
#define LL long long
#define ULL unsigned long long
#define ENDL putchar('\n')
#define DB double
#define lowbit(x) (-(x) & (x))
#define FI first
#define SE second
#define PR pair<int,int>
#define UIN unsigned int
int xchar() {
static const int maxn = 1000000;
static char b[maxn];
static int pos = 0,len = 0;
if(pos == len) pos = 0,len = fread(b,1,maxn,stdin);
if(pos == len) return -1;
return b[pos ++];
}
// #define getchar() xchar()
LL read() {
LL f = 1,x = 0;int s = getchar();
while(s < '0' || s > '9') {
if(s<0)return -1;if(s=='-')f=-f;s = getchar();}
while(s >= '0' && s <= '9') {
x = (x<<1) + (x<<3) + (s^48);s = getchar();}
return f*x;
}
void putpos(LL x) {
if(!x)return ;putpos(x/10);putchar((x%10)^48);}
void putnum(LL x) {
if(!x) {
putchar('0');return ;}
if(x<0) putchar('-'),x = -x;
return putpos(x);
}
void AIput(LL x,int c) {
putnum(x);putchar(c);}
int n,m,s,o,k;
int a,b,c;
LL A_,B_,L_,R_,t;
int Abs(int x) {
return x<0 ? -x:x;}
int dis(int x,int y,int a,int b) {
return Abs(a-x) + Abs(b-y);
}
LL sm(int l,int r) {
return (l+r) *1ll* (r-l+1) / 2;}
bool check(int x,int y,LL A,LL B,LL L,LL R) {
if(A > t || B > t || L > t || R > t) return 0;
if(x == n+1 && y == n) return 1;
if(x < a)
return check(a,b,A+sm(1,dis(x,y,a,b)),B+sm(c+c+1,dis(x,y,a+c,b+c)),
L+sm(c+1,dis(x,y,a,b+c)),R+sm(c+1,dis(x,y,a+c,b)));
if(x >= a+c && y >= b+c)
return check(n+1,n,A+sm(x-a+y-b,n-a+n-b),B+sm(x-a-c+y-b-c,n-a-c+n-b-c),
L+sm(x+y-a-b-c,n+n-a-b-c),R+sm(x+y-a-b-c,n+n-a-b-c));
if(x <= a+c && y < b)
return check(x,b,A+sm(x-a+1,dis(x,y,a,b)),B+sm(a+c-x+c+1,dis(x,y,a+c,b+c)),
L+sm(dis(x,b-1,a,b+c),dis(x,y,a,b+c)),R+sm(a+c-x+1,dis(x,y,a+c,b)));
if(x > a+c && y < b)
return check(x,b,A+sm(x-a+1,dis(x,y,a,b)),B+sm(x-a+1,dis(x,y,a,b)),
L+sm(dis(x,b-1,a,b+c),dis(x,y,a,b+c)),R+sm(x-a-c+1,dis(x,y,a+c,b)));
if(x > a+c && y < b+c)
return check(x,b+c,A+sm(dis(x,y,a,b),dis(x,b+c-1,a,b)),B+sm(dis(x,b+c-1,a+c,b+c),dis(x,y,a+c,b+c)),
L+sm(dis(x,b+c-1,a,b+c),dis(x,y,a,b+c)),R+sm(dis(x,y,a+c,b),dis(x,b+c-1,a+c,b)));
A += sm(dis(x,y,a,b),c+c); B += sm(0,dis(x,y,a+c,b+c));
LL sl = sm(x-a,dis(x,y,a,b+c)) + sm(x-a+1,c);
L += sl; R += sm(y-b,dis(x,y,a+c,b)) + sm(y-b+1,c);
LL ad = sm(dis(x,y,a,b+c),dis(a+c,y,a,b+c)) + sm(c,dis(a+c,y,a,b+c)-1) - sl;
if(L+ad <= R+2) L += ad;
else if(R+ad <= L+2) R += ad;
else {
if(L > R) swap(L,R);
LL nb = R-L - ((R-L)&1); L += nb; ad -= nb;
if(ad & 3) ad -= 2,L += 2;
L += ad>>1; R += ad>>1;
}
return check(a+c+1,b+c,A,B,L,R);
}
int main() {
freopen("elis.in","r",stdin);
freopen("elis.out","w",stdout);
n = read(); t = read();
a = read(); b = read(); c = read()-1;
int x = 1,y = 1;
if(!check(x+1,y,0,0,0,0) && !check(x,y+1,0,0,0,0)) return printf("Again\n"),0;
while(x < n || y < n) {
if(x < n && check(x+1,y,A_,B_,L_,R_)) x ++,putchar('R');
else y ++,putchar('U');
A_ += dis(x,y,a,b); B_ += dis(x,y,a+c,b+c);
L_ += dis(x,y,a,b+c); R_ += dis(x,y,a+c,b);
} ENDL;
return 0;
}
This seems to be a question a few years ago
边栏推荐
- Mfc a dialog calls B dialog function and passes parameters
- [development environment] install the visual studio community 2013 development environment (download the installation package of visual studio community 2013 with update 5 version)
- LeetCode_滑动窗口_中等_395.至少有 K 个重复字符的最长子串
- JMeter script parameterization
- obsidian安装第三方插件——无法加载插件
- Tmall product details interface (APP, H5 end)
- taobao.trades.sold.get-查询卖家已卖出的交易数据(根据创建时间),淘宝店铺卖出订单查询API接口,淘宝R2接口,淘宝oAuth2.0交易接口代码分享
- OpenCV调用USB摄像头的点滴
- taobao. trades. sold. Get query the transaction data that the seller has sold (according to the creation time), Taobao store sales order query API interface, Taobao R2 interface, Taobao oauth2.0 trans
- 3. Function pointers and pointer functions
猜你喜欢

Add vector formula in rich text editor (MathType for TinyMCE, visual addition)

obsidian安装第三方插件——无法加载插件

【C语言】详解指针的初阶和进阶以及注意点(1)

C#代码审计实战+前置知识

一张图彻底掌握prototype、__proto__、constructor之前的关系(JS原型、原型链)

LeetCode 2320. 统计放置房子的方式数

c语言入门--数组

Wechat applet uses towxml to display formula

ONNX+TensorRT:将预处理操作写入ONNX并完成TRT部署

Onnx+tensorrt: write preprocessing operations to onnx and complete TRT deployment
随机推荐
C language exercises - (array)
解决el-radio-group 回显后不能编辑问题
【题解】Educational Codeforces Round 82
JMeter script parameterization
buuctf-pwn write-ups (7)
用户隐私协议有些汉字编码不规范导致网页显示乱码,需要统一找出来处理一下
Reuse and distribution
mathjax 入门(web显示数学公式,矢量的)
Printf function and scanf function in C language
求轮廓最大内接圆
kityformula-editor 配置字号和间距
Arithmetic operations and related exercises in C language
Ad20 cannot select the solution of component packaging in PCB editor
LeetCode 2310. 个位数字为 K 的整数之和
Bit by bit of OpenCV calling USB camera
Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly
Huawei interview question: no palindrome string
Some Chinese character codes in the user privacy agreement are not standardized, which leads to the display of garbled codes on the web page. It needs to be found and handled uniformly
1. Editing weapon VIM
【C语言】详解指针的初阶和进阶以及注意点(1)