当前位置:网站首页>Winter vacation daily question 2022 [week1 not finished]
Winter vacation daily question 2022 [week1 not finished]
2022-06-11 18:00:00 【Hui Xiaoge】
Catalog
2058. Clumsy fingers 【 enumeration 】

#include<bits/stdc++.h>
using namespace std;
string a,b;
typedef long long int LL;
bool check(int sum)
{
string temp;
if(sum==0) temp="0";
while(sum) temp=to_string(sum%3)+temp,sum/=3;
int cnt=0;
for(int i=0;i<b.size();i++) if(temp[i]!=b[i]) cnt++;
if(temp.size()==b.size()&&cnt==1) return true;
return false;
}
int main(void)
{
cin>>a>>b;
for(int i=0;i<a.size();i++)// Enumerate which bit is wrong
{
LL sum=0;
for(int j=0;j<a.size();j++)
{
if(i==j) sum=sum*2+!(a[j]-'0');
else sum=sum*2+a[j]-'0';
}
if(check(sum))
{
cout<<sum<<endl;
return 0;
}
}
return 0;
}
2041. Haystack 【 Difference 】

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int c[N],n,m;
vector<int>ve;
void add(int l,int r,int w)
{
c[l]+=w;
c[r+1]-=w;
}
int main(void)
{
cin>>n>>m;
while(m--)
{
int a,b; cin>>a>>b;
add(a,b,1);
}
for(int i=1;i<=n;i++)
{
c[i]+=c[i-1];
ve.push_back(c[i]);
}
sort(ve.begin(),ve.end());
cout<<ve[n/2];
return 0;
}
2060. Cow beauty pageant 【dfs + thinking 】

Let's talk about the points of different connected blocks , Store in two sets .
Then enumerate the points of the two sets , Find the distance between any two points of two sets .
The shortest distance between two points , Must be Manhattan distance , But the distance between two points in Manhattan may have some obstacles .
But the problem must change to the distance between these two points . Therefore, directly enumerate points to find all Manhattan distances and take one min that will do .
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
const int N=155;
string s[N];
int n,m,cnt;
int dx[4]={
-1,0,0,1};
int dy[4]={
0,-1,1,0};
vector<PII> ve[15];
void dfs(int x,int y,int k)
{
ve[k].push_back({
x,y});
s[x][y]='.';
for(int i=0;i<4;i++)
{
int tempx=x+dx[i];
int tempy=y+dy[i];
if(tempx<0||tempx>=n||tempy<0||tempy>=m) continue;
if(s[tempx][tempy]!='X') continue;
dfs(tempx,tempy,k);
}
}
int solve(PII a,PII b)
{
return abs(a.first-b.first)+abs(a.second-b.second)-1;
}
int main(void)
{
cin>>n>>m;
for(int i=0;i<n;i++) cin>>s[i];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(s[i][j]=='X') dfs(i,j,cnt++);
int ans=1e9;
for(int i=0;i<ve[0].size();i++)
for(int j=0;j<ve[1].size();j++)
ans=min(ans,solve(ve[0][i],ve[1][j]));
cout<<ans;
return 0;
}
2019. Tractor 【 deque 】

Turn it into a graph theory problem to find the shortest path , Because only the edge power 0 and 1, So you can use two-way search directly ,0 Add to the opposite ,1 Join the back of the line .
#include<bits/stdc++.h>
using namespace std;
const int N=1010;
int g[N][N],dist[N][N],st[N][N],n,stx,sty;
int dx[4]={
-1,0,0,1};
int dy[4]={
0,-1,1,0};
int bfs(int x,int y)
{
memset(dist,0x3f,sizeof dist);
dist[x][y]=0;
deque<pair<int,int>>q; q.push_back({
x,y});
while(q.size())
{
auto temp=q.front(); q.pop_front();
x=temp.first,y=temp.second;
if(!x&&!y) return dist[x][y];
if(st[x][y]) continue;
st[x][y]=1;
for(int i=0;i<4;i++)
{
int tempx=x+dx[i];
int tempy=y+dy[i];
if(tempx<0||tempx>=N||tempy<0||tempy>=N) continue;
int w=0;
if(g[tempx][tempy]) w=1;// obstacle
if(dist[tempx][tempy]>dist[x][y]+w)
{
dist[tempx][tempy]=dist[x][y]+w;
if(w) q.push_back({
tempx,tempy});
else q.push_front({
tempx,tempy});
}
}
}
return -1;
}
int main(void)
{
cin>>n>>stx>>sty;
while(n--)
{
int a,b; cin>>a>>b;
g[a][b]=1;
}
cout<<bfs(stx,sty);
return 0;
}
边栏推荐
- [practical Script] obtain the line number of a file, and then delete the file content.
- Tle6389-2g V50's unique pwm/pfm control scheme has a duty cycle of up to 100%, forming a very low differential pressure - keshijin mall
- 6-5 count the number of words (file) (*)
- tidb-ddl的速度的调整
- 测试基础之:黑盒测试
- mariadb spider分片引擎初体验
- Common shortcut keys for Hello go (x) and GoLand
- 7-1 均是素数
- 夜神安装apk,以及bp代理
- Spring 2021 daily question [week3 not finished]
猜你喜欢

【先收藏,早晚用得到】49个Flink高频面试题系列(二)

合并K个升序链表---2022/02/26

After class, I looked at the document and went back to the lab. I picked up the forgotten SQL operators again

括号生成---2022/02/25

ADB command learning notes

聚类方法汇总

Test and analysis of tidb write hotspot

Ffmpeg hardware codec NVIDIA GPU

Chorus翻译

【先收藏,早晚用得到】100个Flink高频面试题系列(一)
随机推荐
threejs利用indexeddb缓存加载glb模型
spawn ./ gradlew EACCES at Process. ChildProcess._ handle. onexit
简单理解事件
tidb-cdc创建任务报错 Unknown or incorrect time zone
[foundation of deep learning] learning of neural network (3)
Bracket generation ---2022/02/25
tidb-cdc日志tables are not eligible to replicate
vulhub
Comparison of mongoose in express, KOA and egg
删除链表的倒数第N个节点---2022/02/22
Expérience initiale du moteur de segmentation de l'araignée mariadb
[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (II)
Kubernetes deploys elk and collects container logs using filebeat
tidb-cdc同步mysql没有的特性到mysql时的处理
【先收藏,早晚用得到】100个Flink高频面试题系列(一)
7-2 h0107. Pig-Latin
Summary of clustering methods
Service学习笔记03- 前台服务实战
Service学习笔记04- 其他服务实现方式与替代方式
Rtsp/onvif protocol easynvr video platform arm version cross compilation process and common error handling