当前位置:网站首页>大二上第三周学习笔记
大二上第三周学习笔记
2022-07-26 09:20:00 【Alex Su (*^▽^*)】
B. Orac and Medians(思维)
非常非常思维的一道题 不好想
首先注意到一个k和一个大于等于k的数,可以变成k,接着这两个数可以把相邻的第三个大于等于k的数变成k
所以我们可以把所有的数变成大于等于k的数,之后就可以全部变成k
那么这么变成大于等于k的数呢
可以发现,两个相邻的大于等于k的数如果存在,那么就可以把第三个数变成大于等于k,接着第四个数
不相邻的话,就是三个数,左右大于等于k也行
所以判一下这两种情况是否存在就行了
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
const int N = 1e5 + 10;
int a[N], n, k;
int main()
{
int T; scanf("%d", &T);
while(T--)
{
int ans = -1;
scanf("%d%d", &n, &k);
_for(i, 1, n)
{
scanf("%d", &a[i]);
if(a[i] == k) ans = 0;
}
if(ans == -1)
{
puts("no");
continue;
}
if(n == 1)
{
puts("yes");
continue;
}
rep(i, 1, n)
if(a[i] >= k && a[i + 1] >= k)
ans = 1;
rep(i, 1, n - 1)
if(a[i] >= k && a[i + 2] >= k)
ans = 1;
puts(ans ? "yes" : "no");
}
return 0;
}C. The Football Season(枚举)
我自己想的时候用了拓展欧几里得,然而WA了
看了题解很巧妙,直接枚举y的值是多少
y的值有一个上限,就是w
当y大于等于w时,可以证明是有更优的策略的
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
typedef long long ll;
int main()
{
ll n, p, w, d;
scanf("%lld%lld%lld%lld", &n, &p, &w, &d);
for(ll y = 0; y < w; y++)
{
ll x = (p - d * y) / w;
if(w * x + d * y == p && x >= 0 && x + y <= n)
{
printf("%lld %lld %lld\n", x, y, n - x - y);
return 0;
}
}
puts("-1");
return 0;
}C. Ice Cave(bfs + 思维)
如果终点是点的话
走到终点,然后走到另一个点,再回来就行了
所以就正常bfs就行了,走过的设为×
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
const int N = 500 + 10;
int x1, y3, x2, y2, n, m;
struct node { int x, y; };
int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
char s[N][N];
void print()
{
_for(i, 1, n) puts(s[i] + 1);
puts("");
}
bool bfs()
{
queue<node> q;
q.push(node{x1, y3});
while(!q.empty())
{
print();
node u = q.front(); q.pop();
int x = u.x, y = u.y;
rep(i, 0, 4)
{
int xx = x + dir[i][0], yy = y + dir[i][1];
if(xx < 1 || xx > n || yy < 1 || yy > m) continue;
if(s[xx][yy] == 'X')
{
if(xx == x2 && yy == y2) return true;
}
else
{
s[xx][yy] = 'X';
q.push(node{xx, yy});
}
}
}
return false;
}
int main()
{
scanf("%d%d", &n, &m);
_for(i, 1, n) scanf("%s", s[i] + 1);
scanf("%d%d%d%d", &x1, &y3, &x2, &y2);
puts(bfs() ? "YES" : "NO");
return 0;
}边栏推荐
猜你喜欢

JS output diamond on the console
![[MySQL] detailed explanation of redo log, undo log and binlog (4)](/img/67/6e646040c1b941c270b3efff74e94d.png)
[MySQL] detailed explanation of redo log, undo log and binlog (4)

ext3文件系统的一个目录下,无法创建子文件夹,但可以创建文件

围棋智能机器人阿法狗,阿尔法狗机器人围棋

Cat installation and use

Bloom filter

Announcement | FISCO bcos v3.0-rc4 is released, and the new Max version can support massive transactions on the chain

【线上死锁分析】由index_merge引发的死锁事件

Innovus卡住,提示X Error:

Vertical search
随机推荐
Tornado multi process service
JS - DataTables control on the number of displays per page
[use of final keyword]
Bloom filter
STM32+MFRC522完成IC卡号读取、密码修改、数据读写
力扣刷题,三数之和
字节缓冲流&字符流详解
ZXing简化版,转载
Paper notes: knowledge map kgat (unfinished temporary storage)
原根与NTT 五千字详解
省政府召开全省高温天气安全防范工作电视电话会议
Pat grade a a1013 battle over cities
"Could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32"
ext4文件系统打开了DIR_NLINK特性后,link_count超过65000的后使用link_count=1来表示数量不可知
2022 Shanghai safety officer C certificate examination questions and mock examination
Sliding window, double pointer, monotone queue, monotone stack
Codeworks DP collection
Redis principle and use - Basic Features
【无标题】
滑动窗口、双指针、单调队列、单调栈