当前位置:网站首页>Study notes of the third week of sophomore year
Study notes of the third week of sophomore year
2022-07-26 09:55:00 【Alex Su (*^▽^*)】
B. Orac and Medians( thinking )
A very, very thinking problem I don't want to
First notice a k And a greater than or equal to k Number of numbers , Can become k, Then these two numbers can make the adjacent third greater than or equal to k The number becomes k
So we can change all numbers to be greater than or equal to k Number of numbers , Then it can all become k
Then it becomes greater than or equal to k The number of?
You can find , Two adjacent ones are greater than or equal to k If the number of exists , Then you can change the third number to be greater than or equal to k, Then the fourth number
If not adjacent , It's three numbers , Left and right greater than or equal to k It's OK
So judge whether these two situations exist
#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( enumeration )
I used extended Euclid when I thought about it myself , However WA 了
After reading the solution, it's very clever , Direct enumeration y What's the value of
y The value of has an upper limit , Namely w
When y Greater than or equal to w when , It can be proved that there is a better strategy
#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 + thinking )
If the end point is point
Go to the end , Then walk to another point , Just come back
So it's normal bfs That's it , Set passed as ×
#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;
}
边栏推荐
- 云原生(三十六) | Kubernetes篇之Harbor入门和安装
- 【荧光字效果】
- Qt随手笔记(三)在vs中使用QtCharts画折线图
- js 表格自动循环滚动,鼠标移入暂停
- 服务发现原理分析与源码解读
- Fiddler packet capturing tool for mobile packet capturing
- Rowselection emptying in a-table
- 挡不住了,纯国产PC已就位,美国的软硬件体系垄断正式被破
- 【Datawhale】【机器学习】糖尿病遗传风险检测挑战赛
- Matlab Simulink realizes fuzzy PID control of time-delay temperature control system of central air conditioning
猜你喜欢
SSG framework Gatsby accesses the database and displays it on the page
Due to fierce competition in the new market, China Mobile was forced to launch a restrictive ultra-low price 5g package
服务发现原理分析与源码解读
服务发现原理分析与源码解读
[fluorescent character effect]
[datawhale] [machine learning] Diabetes genetic risk detection challenge
苹果独占鳌头,三星大举复兴,国产手机在高端市场颗粒无收
Installation and use of cocoapods
The diagram of user login verification process is well written!
2021年山东省中职组“网络空间安全”B模块windows渗透(解析)
随机推荐
MFC handy notes
The whole process of server environment configuration
Solve the problem of storing cookies in IE7 & IE8
2021年山东省中职组“网络空间安全”B模块windows渗透(解析)
R语言ggplot2可视化: 将图例标题(legend title)对齐到ggplot2中图例框的中间(默认左对齐、align legend title to middle of legend)
(2) Hand eye calibration of face scanner and manipulator (eye out of hand: nine point calibration)
Alibaba cloud technology expert haochendong: cloud observability - problem discovery and positioning practice
挡不住了,纯国产PC已就位,美国的软硬件体系垄断正式被破
苹果独占鳌头,三星大举复兴,国产手机在高端市场颗粒无收
Docker configuring MySQL Cluster
asp. Net using redis cache (2)
M-ary number STR to n-ary number
高斯消元
JS judge the data types object.prototype.tostring.call and typeof
新增市场竞争激烈,中国移动被迫推出限制性超低价5G套餐
Gauss elimination solves the inverse of matrix (Gauss)
Network flow learning notes
Draw arrows with openlayer
Server and client dual authentication (2)
网络流学习笔记