传送门

A. Stones

签到。

B. Alice and the List of Presents

单独考虑每个数的贡献即可。

答案为\((2^{m}-1)^n\)。

C. Labs

构造就类似于:

1 6 7

2 5 8

3 4 9

这样就行了。

证明我也不会,但感觉这样能使得每一行都较为均衡。

Code
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
// #define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 305; int n;
int mp[N][N]; void run() {
cin >> n;
for(int j = 1; j <= n; j++) {
int st = (j - 1) * n + 1;
if(j & 1) {
for(int i = n; i >= 1; i--, st++) {
mp[i][j] = st;
}
} else {
for(int i = 1; i <= n; i++, st++) {
mp[i][j] = st;
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
cout << mp[i][j] << " \n"[j == n];
}
}
} int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
#ifdef Local
freopen("../input.in", "r", stdin);
freopen("../output.out", "w", stdout);
#endif
while(cin >> n) run();
return 0;
}

D. Alice and the Doll

题意:

给出一个\(n\cdot m,n,m\leq 10^5\)大小的网格图,上面有些位置可能有障碍。

现在要求,每个格子只能经过一次,并且在每个格子有两个选择:直走或者右转。初始位于\((1,1)\)位置,方向为向右。

问能否走遍所有非障碍的点。

思路:

把题读成一个位置可以经过多次,但只能右转一次,想了一小时假题

因为只能经过一次,那么我们路线肯定是“回路”型的,并且肯定是贪心地走。

那么我们每行每列存障碍,然后模拟这个过程就行。

代码中用了一个矩形表示当前范围。注意每次删障碍时肯定要删除一个矩形,矩形内如果有空地那就不合法,因为不可能再走过去了。

注意矩形范围的更新。

细节见代码:

Code
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
// #define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5; int n, m, k;
set <int> col[N], row[N]; bool del(int up, int down, int left, int right) {
for(int i = up; i <= down; i++) {
for(int j = left; j <= right; j++) {
if(row[i].find(j) == row[i].end()) return false;
row[i].erase(j);
col[j].erase(i);
--k;
}
}
return true;
} void run() {
for(int i = 1; i <= k; i++) {
int x, y; cin >> x >> y;
col[y].insert(x);
row[x].insert(y);
}
int dir = 0;
int up = 1, down = n, left = 1, right = m;
int D = 0;
int x = 1, y = 1;
while(k) {
if(dir == 0) {
auto it = row[x].begin();
if(it == row[x].end()) {
y = right;
} else {
int p = *it;
if(!del(up, down, p, right)) {
cout << "No";
return;
}
right = y = p - 1;
}
left += D;
} else if(dir == 1) {
auto it = col[y].begin();
if(it == col[y].end()) {
x = down;
} else {
int p = *it;
if(!del(p, down, left, right)) {
cout << "No";
return;
}
down = x = p - 1;
}
up += D;
} else if(dir == 2) {
auto it = row[x].rbegin();
if(it == row[x].rend()) {
y = left;
} else {
int p = *it;
if(!del(up, down, left, p)) {
cout << "No";
return;
}
left = y = p + 1;
}
right -= D;
} else {
auto it = col[y].rbegin();
if(it == col[y].rend()) {
x = up;
} else {
int p = *it;
if(!del(up, p, left, right)) {
cout << "No" << '\n';
return;
}
up = x = p + 1;
}
down -= D;
}
dir = (dir + 1) % 4;
D = 1;
// cout << up << ' ' << down << ' ' << left << ' ' << right << '\n';
}
cout << "Yes" << '\n';
} int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
#ifdef Local
freopen("../input.in", "r", stdin);
freopen("../output.out", "w", stdout);
#endif
while(cin >> n >> m >> k) run();
return 0;
}

E. Alice and the Unfair Game

题意:

现有\(n\)个方格排成一列,同时给出一个序列\(a\),\(a_i\)表示第\(i\)次时敲打\(a_i\)这个方格。

现有个玩偶在这个方格上面走,每次敲打后可以向相邻方格走一步或者留在原地。并规定一开始可以移动一步。

问存在多少对\((x,y)\),表示玩偶一开始在\(x\),最后在\(y\)位置,并且中间不会被敲打。

思路:

有一个观察:

  • 对于一个点\(x\),若其最远向右能走到\(y\),那么最终走到\(x\)~\(y\)之间的方格都为合法答案。
  • 向左延申同理。
感性证明

证明的话可以感性理解一下,因为在一个时间点只能敲打一次,倒过来考虑,因为最后能够停留在$y$,假设我们是从$y-1$走过来,那么必然最后一次不会敲打$y-1$这个位置,那直接停在这个位置即可;如果我们一直卡在$y$,那也是可以往前走的。

 

所以现在问题的关键就是对于每个位置,如何快速找到向左、向右延申的最远位置。

因为这个题跟时间有很大关系,所以我们考虑用二维坐标\((x,y)\)表示在\(x\)时刻位于第\(y\)个方格。那么敲打点就相当于二维平面上的一个障碍。

问题就变为:我们从\((0,y)\)出发,每次可以向上、向右、向下走一步,不能经过障碍,能走到的最上/最下的位置是多少。

以最大举例:我们采用贪心的策略,用vector存储同一斜率上的所有障碍点,然后二分找到障碍点位置\((x_i,y_i)\),那我们只能走到\((x_i,y_i-1)\);之后快速找到下一个\(y_j\not ={y_i}\)的时间点(预处理下一个位置),走过去即可。

详细细节见代码:

Code
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
// #define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5 + 5, base = 1e5; int n, m;
int a[N], nxt[N];
vector<int> v1[N], v2[N];
int Max[N], Min[N]; void run() {
for(int i = 1; i < N; i++) v1[i].clear(), v2[i].clear();
for(int i = 1; i <= m; i++) {
int x; cin >> x;
v1[i - x + base].push_back(i);
v2[i + x].push_back(i);
a[i] = x;
}
if(n == 1 && *max_element(a + 1, a + m + 1) == 1) {
cout << 0 << '\n';
return;
}
nxt[m] = m + 1;
for(int i = m - 1; i >= 1; i--) {
if(a[i] == a[i + 1]) nxt[i] = nxt[i + 1];
else nxt[i] = i + 1;
}
for(int i = 1; i <= n; i++) {
int x = 0, y = i;
while(1) {
int k = x - y + base;
auto it = lower_bound(v1[k].begin(), v1[k].end(), x + 1);
if(it == v1[k].end()) {
y += m + 1 - x;
break;
}
int p = it - v1[k].begin();
p = v1[k][p];
x = nxt[p] - 1, y = a[p] - 1;
}
Max[i] = min(y, n);
}
for(int i = 1; i <= n; i++) {
int x = 0, y = i;
while(1) {
int k = x + y;
auto it = lower_bound(v2[k].begin(), v2[k].end(), x + 1);
if(it == v2[k].end()) {
y -= m + 1 - x;
break;
}
int p = it - v2[k].begin();
p = v2[k][p];
x = nxt[p] - 1, y = a[p] + 1;
}
Min[i] = max(1, y);
}
ll ans = 0;
for(int i = 1; i <= n; i++) {
ans += (Max[i] - Min[i] + 1);
}
cout << ans << '\n';
} int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
#ifdef Local
freopen("../input.in", "r", stdin);
freopen("../output.out", "w", stdout);
#endif
while(cin >> n >> m) run();
return 0;
}

注意一下,当\(n>1\)时,每个位置肯定至少存在一个解。但是当\(n=1\)时,因为没有周转的地方,所以可能没有解,所以我们需要特判一下。

Codeforces Round #593 (Div. 2)的更多相关文章

  1. Codeforces Round #593 (Div. 2) D. Alice and the Doll

    题目:http://codeforces.com/problemset/problem/1236/D思路:机器人只能按照→↓←↑这个规律移动,所以在当前方向能够前进的最远处即为界限,到达最远处右转,并 ...

  2. Codeforces Round #593 (Div. 2) C. Labs A. Stones

    题目:https://codeforces.com/contest/1236/problem/A 思路:两种操作收益都是3 且都会消耗b 操作2对b消耗较小 则可优先选择操作2 再进行操作1 即可得到 ...

  3. Codeforces Round #593 (Div. 2) C. Labs

    题目:https://codeforces.com/contest/1236/problem/C 思路:将 n ^ 2 个 lab 平分为 n 个 group group A 和 B 组成的 有序对 ...

  4. Codeforces Round #593 (Div. 2)D(螺旋形模拟)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;vector<int>po[100 ...

  5. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. C# 调用OpenCVSharp报错“尝试读取或写入受保护的内存。这通常指示其他内存已损坏”

    一.描述问题 当托管代码调用非托管代码的时候,经常会出现如下报错:“尝试读取或写入受保护的内存.这通常指示其他内存已损坏”. 二.原因分析 由于非托管代码的内存指针的回收是由非托管代码自身手动完成的, ...

  2. 对Python中一些“坑”的总结及技巧

    一.赋值即定义 1.运行以下代码会出现报错 #!/usr/bin/env python #_*_conding:utf-8_*_ x = 100 def outer(): def inner(): x ...

  3. 利用zabbix API 统计一段时间内监控项的均值和峰值

    #coding:utf-8 #给定主机IP获取一段时间内cpu的均值和峰值并写入文件(txt,可以跑完后直接把后缀名改为csv以表格形式打开):需要指定IP文件 import requests imp ...

  4. reports buileder 触发器的写法

    触发器写法: function CF_SHOULD_BACK_TIMEFormula return Number is--其他:取MES工时按工段分别统计产量.投入工时合计:应回报工时=移动数量*[∑ ...

  5. 2、nio的例子实践

    下面的例子,说明了,nio中的三大核心类的基本使用.buffer,channel,selector package com.shengsiyuan.nio; import org.junit.Test ...

  6. 测试工程师如何使用 CODING 进行测试管理

    CODING 为您的企业提供从概念到软件开发再到产品发布的全流程全周期软件研发管理,为您的研发团队提供全程助力,帮助研发团队捋清需求.不断迭代.快速反馈并能实时追踪项目进度直到完成.同时 CODING ...

  7. Redis内存数据库在Exchange会议室的整体应用架构

    注:本文是别人写的,感觉写得很好就转过来,版权归原作者所有哦,谁知道出处可以告诉我,谢谢. 根据以上的会议室应用现状分析,该架构的核心是把历史发生的会议室申请数据定时同步到Redis内存数据库中,对于 ...

  8. 在windows上用apache+mod_wsgi服务部署django项目

    之前一直在本地跑django项目,最近尝试在服务器上部署项目,目前已经成功部署,也花了好多时间,这里跟大家交流一下,希望对像我一样的新手有帮助. 一.配置环境: 1.Python版本3.7 2.服务器 ...

  9. java 后台上传文件

    java 后台上传文件 public static String uploadFile(File file, String RequestURL) throws IOException { Strin ...

  10. PyCharm 2019 2.3 软件安装教程(1.补丁破解2.破解码)

    一:补丁破解 PyCharm 2019 2.3 下载地址 https://pan.baidu.com/s/1HaWFcbO-x4vZuT6mVC0AGA 提取码:elu7 更多破解教程微信公众号关注“ ...