当前位置:网站首页>2022/7/15
2022/7/15
2022-07-19 10:52:00 【killer_ queen4804】
P6121 [USACO16OPEN]Closing the Farm G - Luogu | New ecology of computer science education (luogu.com.cn) Union checking set
I've done this problem before , Not now ,,, The key is to think about the opposite , Turn positive closing into negative opening , from n-1 Start recording how many edges are added , If the number of sides added is points -1, Then it is connected
2022/1/29_killer_queen4804 The blog of -CSDN Blog
#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const ll mod=998244353;
ll n,m,s[200005],ans[200005],vis[200005],t[200005];
ll head[500005],cnt;
struct Edge{
ll next,from,to;
}edge[500005];
void addedge(ll from,ll to){
edge[++cnt].from=from;
edge[cnt].to=to;
edge[cnt].next=head[from];
head[from]=cnt;
}
ll findd(ll x){
return x==s[x]?x:s[x]=findd(s[x]);
}
int main(){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=m;i++){
ll u,v;
scanf("%lld%lld",&u,&v);
addedge(u,v);
addedge(v,u);
}
for(int i=1;i<=n;i++) scanf("%lld",&t[i]);
for(int i=1;i<=n;i++) s[i]=i;
vis[t[n]]=1;
ans[n]=1;
ll k=0;
for(int i=n-1;i>=1;i--){
vis[t[i]]=1;
for(int j=head[t[i]];j;j=edge[j].next){
if(vis[edge[j].to]){
ll x=findd(t[i]),y=findd(edge[j].to);
if(x!=y){
k++;
s[x]=y;
}
}
}
if(k==n-i) ans[i]=1;
else ans[i]=0;
}
for(int i=1;i<=n;i++)
if(ans[i]) printf("YES\n");
else printf("NO\n");
return 0;
}
Palindromic Numbers structure
The number output must be the same as the number given , That is to say, it has to be n position , Consider taking 99 Come on , You can consider 111 This palindrome number , So the answer is 12, And then you can see that 999 The answer is 112,9999 The answer is 1112, The number of digits is the same , And most of the scores can be one more 111... Subtract the given number to get the answer , But compared to 1..2 A small number is not enough , So you can use that 1000..01 The answer is obtained by subtracting the given number from the number in this form
#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const ll mod=998244353;
ll t,n;
char s[100005],c[100005],ans[100005],ch[100005];
bool pd(){
for(int i=1;i<=n;i++){
if(s[i]<ch[i]) return 0;
if(s[i]>ch[i]) return 1;
}
return 1;
}
int main(){
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
scanf("%s",s+1);
for(int i=1;i<n;i++) ch[i]='1';ch[n]='2';
if(pd()){
for(int i=1;i<=n+1;i++) c[i]='1';
}
else{
for(int i=2;i<=n;i++) c[i]='0';c[1]=c[n+1]='1';
}
for(int i=n;i>=1;i--){
if(c[i+1]<s[i]){
c[i+1]+=10;
ll cnt=i;c[cnt]--;
while(cnt>0&&c[cnt]<0){
c[cnt]+=10;
c[--cnt]--;
}
}
//cout<<c[i+1]<<" "<<s[i]<<" "<<(c[i+1]-'0')-(s[i]-'0')<<endl;
ans[i]=(c[i+1]-'0')-(s[i]-'0')+'0';
}
for(int i=1;i<=n;i++) cout<<ans[i];cout<<'\n';
}
return 0;
}
Helping the Nature Difference
After reading the title, I have no way to start , But find out a difference group and you can find , The three operations previously pressed have become
b[1]-1,b[i]+1;b[1]+1;b[i]-1; These three operations , In this way, we try to use the 1 Kind of operation , Because you can change two at the same time , Then use the other two , Our goal is to change the difference array into 0, So sometimes b[i](i>1) It will be less than 0 And the first operation alone cannot make b[i]=0, So we should use the second operation to make b[1] increase ,b[i] Greater than or equal to 0 Then you can use the third operation to eliminate it in turn , The code is directly simplified into oneortwo formulas , But it all means the same
#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const ll mod=998244353;
ll t,n,a[200005],b[200005];
int main(){
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
ll sum=0,ans=0;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]),b[i]=a[i]-a[i-1];
if(i>1){
sum+=b[i]<0?abs(b[i]):0;
ans+=abs(b[i]);
}
}
ans+=abs(b[1]-sum);
printf("%lld\n",ans);
}
return 0;
}
边栏推荐
- 反向散射通信的未来应用与技术挑战
- 空天地海一体化网络体系架构与网络切片技术
- How to use SVG to make text effects arranged along any path
- unity3d如何利用asset store下载一些有用的资源包
- Game theory (Depu) and investment (40/100)
- [acwing] game 60 c-acwing 4496 eat fruit
- SAP S4 Material Management 库存模块 MARD 数据库表读取技术细节介绍
- C serialport configuration and attribute understanding
- About hping streaming test tool
- High number_ Chapter 1 space analytic geometry and vector algebra__ Distance from point to plane
猜你喜欢

Redis集群、一主二从三哨兵的搭建

「百度一面」怒喷面试官!不就是树遍历时增加一个行号?

Leetcode ugly number problem solution

Structure the combat battalion | module 7

leetcode-08

Take a look at this ugly face | MathWorks account unavailable - technical issue

人大、微软等提出InclusiveFL:异构设备上的包容性联邦学习

Design and Simulation of intelligent storage cabinet control system

分类任务中的类别不平衡问题

Leetcode丑数题解
随机推荐
6G中的卫星通信高效天基计算技术
发明闪存能赚多少钱?这是一个日本的狗血故事
ENVI_ Idl: use the inverse distance weight method to select the nearest n points for interpolation (bottom implementation) and output them to GeoTIFF format (the effect is equivalent to the inverse di
MySQL query error
SAP AppGyver 的 Universal Theme System 使用介绍
[acwing] game 60 c-acwing 4496 eat fruit
Avi 部署使用指南(2):Avi 架构概述
leetcode-08
2022/7/15
Pytoch realizes multi-layer perceptron manually
[Acwing] 第 60 场周赛 C-AcWing 4496. 吃水果
IP SAN拥有独立的文件系统,应用服务器通过网络共享协议访问到IP SAN后,可以对文件系统中的文件进行读写操作
金鱼哥RHCA回忆录:CL210描述OPENSTACK控制平面--识别overclound控制平台服务+章节实验
关于hping打流测试工具
多元线性回归详解
[PostgreSQL] PostgreSQL 15 optimizes distinct
C serialport configuration and attribute understanding
电商销售数据分析与预测(日期数据统计、按天统计、按月统计)
从“被动”到“主动”,ZETA技术助力“RFID2.0”升级该如何实现?
Transplant Wu Enda's deep learning 01 machine learning and neural network second week neural network basic programming homework elective homework to pycharm