「ABC 197A」Rotate

Link.

略。

#include<bits/stdc++.h>
using namespace std;
int main(){
char a,b,c;cin>>a>>b>>c;cout<<b<<c<<a;
return 0;
}

「ABC 197B」Visibility

Link.

扫。

#include<bits/stdc++.h>
using namespace std;
int main(){
int h,w,x,y;cin>>h>>w>>x>>y;vector<string> a(h);--x,--y;
for(string &i:a)cin>>i;
int ans=0;
for(int i=x;~i;--i)if(a[i][y]=='.')++ans;/*,printf("(%d %d)\n",i+1,y+1);*/else break;
for(int i=x;i<h;++i)if(a[i][y]=='.')++ans;/*,printf("(%d %d)\n",i+1,y+1);*/else break;
for(int i=y;~i;--i)if(a[x][i]=='.')++ans;/*,printf("(%d %d)\n",x+1,i+1);*/else break;
for(int i=y;i<w;++i)if(a[x][i]=='.')++ans;/*,printf("(%d %d)\n",x+1,i+1);*/else break;
cout<<ans-3;
return 0;
}

「ABC 197C」ORXOR

Link.

二进制枚举暴力算。

#include<bits/stdc++.h>
using namespace std;
long long n,a[30],b[30];
int main(){
scanf("%lld",&n);for(long long i=1;i<=n;++i){scanf("%lld",&a[i]);}
long long up=(1<<n),ans=1e18;
for(long long i=0;i<=up;++i){
long long ct=1;
b[ct]=a[1];
for(long long j=2;j<=n;++j)if(((i>>(j-1))&1)^((i>>(j-2))&1))b[++ct]=a[j];else b[ct]|=a[j];
long long tmp=0;
for(long long j=1;j<=ct;++j)tmp^=b[j];
ans=min(ans,tmp);
}
printf("%lld\n",ans);
return 0;
}

「ABC 197D」Opposite

Link.

数学题,不会,而且读不太懂题。

// Oops, something went wrong.

「ABC 197E」Traveler

Link.

这个题看起来就很 关路灯

对于每一种颜色(这里的颜色是指我们已经收集完了上一种颜色,正在收集的颜色),我们不可能走过而不拾。

于是收完一种颜色后,我们一定是这种颜色的的最左 / 右边。

然后就可以 DP 了;设 \(f_{i,0\text{ or }1}\) 为拾 \(i\)-th 颜色,在左 / 右,转移显然。

/*
Denote f[i][0/1] for the minimum time, that we finish collecting the i-th color and we're at the left/right (0/1) endpoint.
f[i][0]=min( f[las][0]+Dist( R[las],L[i] ),f[las][1]+Dist( L[las],L[i] ) )+R[i]-L[i];
f[i][1]=min( f[las][0]+Dist( R[las],R[i] ),f[las][1]+Dist( L[las],R[i] ) )+R[i]-L[i];
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF=1e18;
int n;
LL f[200010][2],L[200010],R[200010];
int main()
{
scanf("%d",&n);
for( int i=1;i<=n;++i ) L[i]=INF,R[i]=-INF;
for( int i=1;i<=n;++i )
{
LL pos;
int color;
scanf( "%lld %d",&pos,&color );
L[color]=min( pos,L[color] );
R[color]=max( pos,R[color] );
}
#define Dist( x,y ) ( LL( abs( ( x )-( y ) ) ) )
for( int i=1,las=0;i<=n+1;++i )
{
if( L[i]!=INF )
{
f[i][0]=min( f[las][0]+Dist( R[las],L[i] ),f[las][1]+Dist( L[las],L[i] ) )+R[i]-L[i];
f[i][1]=min( f[las][0]+Dist( R[las],R[i] ),f[las][1]+Dist( L[las],R[i] ) )+R[i]-L[i];
las=i;
}
}
printf( "%lld\n",f[n+1][1] );
return 0;
}

「ABC 197F」Construct a Palindrome

Link.

相当于是从 \(1\) 和 \(n\) 同时走,每次走字母一样的边,直接双向 BFS 即可。

#include<bits/stdc++.h>
using namespace std;
#define turn(c) ((c)-'a')
#define fs first
#define sc second
const int INF=1e9;
vector<int> suf[1010][26];
int n,m,ans=INF,vis[1010][1010];
struct node
{
int fs,sc,val;
node(int A=0,int B=0,int C=0){fs=A,sc=B,val=C;}
};
queue<node> q;
int main()
{
// freopen("in.in","r",stdin);
// freopen("my.out","w",stdout);
scanf("%d %d",&n,&m);
vis[1][n]=1;
for(int i=1;i<=m;++i)
{
int x,y;
scanf("%d %d",&x,&y);
char c=getchar();
while(c<'a' || c>'z') c=getchar();
suf[x][turn(c)].emplace_back(y);
suf[y][turn(c)].emplace_back(x);
}
q.emplace(node(1,n,0));
while(!q.empty())
{
int one=q.front().fs,ano=q.front().sc,lav=q.front().val;
q.pop();
if(lav==ans) return printf("%d\n",ans<<1),0;
for(int i=0;i<26;++i)
{
for(int exone:suf[one][i])
{
for(int exano:suf[ano][i])
{
if(exone==ano || exano==one) return printf("%d\n",lav<<1|1),0;
if(exone==exano) ans=lav+1;
if(!vis[exone][exano])
{
vis[exone][exano]=1;
q.emplace(node(exone,exano,lav+1));
}
}
}
}
}
printf("-1\n");
return 0;
}

Solution Set -「ABC 197」的更多相关文章

  1. Solution Set -「ABC 217」

      大家好屑兔子又来啦! [A - Lexicographic Order]   说个笑话,\(\color{black}{\text{W}}\color{red}{\text{alkingDead} ...

  2. Diary / Solution Set -「WC 2022」线上冬眠做噩梦

      大概只有比较有意思又不过分超出能力范围的题叭.   可是兔子的"能力范围" \(=\varnothing\) qwq. 「CF 1267G」Game Relics   任意一个 ...

  3. Solution Set -「ARC 107」

    「ARC 107A」Simple Math   Link.   答案为: \[\frac{a(a+1)\cdot b(b+1)\cdot c(c+1)}{8} \] 「ARC 107B」Quadrup ...

  4. Solution -「ABC 219H」Candles

    \(\mathcal{Description}\)   Link.   有 \(n\) 支蜡烛,第 \(i\) 支的坐标为 \(x_i\),初始长度为 \(a_i\),每单位时间燃烧变短 \(1\) ...

  5. Solution -「ABC 215H」Cabbage Master

    \(\mathcal{Description}\)   Link.   有 \(n\) 种颜色的,第 \(i\) 种有 \(a_i\) 个,任意两球互不相同.还有 \(m\) 个盒子,每个盒子可以被放 ...

  6. Solution -「ABC 213G」Connectivity 2

    \(\mathcal{Description}\)   Link.   给定简单无向图 \(G=(V,E)\),点的编号从 \(1\) 到 \(|V|=n\).对于 \(k=2..n\),求 \(H= ...

  7. Solution -「ABC 213H」Stroll

    \(\mathcal{Description}\)   Link.   给定一个含 \(n\) 个结点 \(m\) 条边的简单无向图,每条边的边权是一个常数项为 \(0\) 的 \(T\) 次多项式, ...

  8. Solution -「ABC 217」题解

    D - Cutting Woods 记录每一个切割点,每次求前驱后驱就好了,注意简单判断一下开闭区间. 考场上采用的 FHQ_Treap 无脑莽. #include <cstdio> #i ...

  9. 「ABC 249Ex」Dye Color

    考虑停时定理. 初始势能为 \(\sum \Phi(cnt_i)\),末势能为 \(\Phi(n)\),我们希望构造这样一个 \(\Phi:Z\to Z\) 函数,使得每一次操作期望势能变化量为常数. ...

  10. Note -「Lagrange 插值」学习笔记

    目录 问题引入 思考 Lagrange 插值法 插值过程 代码实现 实际应用 「洛谷 P4781」「模板」拉格朗日插值 「洛谷 P4463」calc 题意简述 数据规模 Solution Step 1 ...

随机推荐

  1. boot 项目启动:Error starting ApplicationContext. To display the conditions report re-run

    Error starting ApplicationContext. To display the conditions report re-run 问题描述 boot 工程启动不了 原因分析: 以后 ...

  2. 逍遥自在学C语言 | 指针和数组的关联

    前言 指针和数组之间存在着紧密的关系.在本文中,我们将探讨指针和数组的关系.指针算术和数组遍历.多维数组与指针以及指针数组和数组指针. 一.人物简介 第一位闪亮登场,有请今后会一直教我们C语言的老师 ...

  3. Pinot2的开发者社区和教程

    目录 文章背景: Pinot 2 是任天堂公司于2018年发布的一款游戏机,采用了基于马里奥兄弟游戏<塞尔达传说:荒野之息>的开放世界操作系统,并推出了许多创新的功能,例如"超级 ...

  4. 跟着 GPT-4 从0到1学习 Golang 并发机制(二)

    btw: 我的个人博客网站 目录 一.前言 二.开聊 2.1 Golang 中的 sync 包 - Mutex, RWMutex 和 WaitGroup 2.2 条件变量 sync.Cond 2.3 ...

  5. Blazor前后端框架Known-V1.2.7

    V1.2.7 Known是基于C#和Blazor开发的前后端分离快速开发框架,开箱即用,跨平台,一处代码,多处运行. Gitee: https://gitee.com/known/Known Gith ...

  6. 2021-7-12 VUE的生命周期

    挂载: beforeCreate created beforeMount mounted:el挂载到实例上时运行 更新: beforeUpdate updated 销毁: beforeDestory ...

  7. Blazor前后端框架Known-V1.2.8

    V1.2.8 Known是基于C#和Blazor开发的前后端分离快速开发框架,开箱即用,跨平台,一处代码,多处运行. Gitee: https://gitee.com/known/Known Gith ...

  8. <学习笔记> 关于二项式反演

    1 容斥原理的式子: \[|A1∪A2∪...∪An|=\sum_{1≤i≤n}|Ai|−\sum_{1≤i<j≤n}|Ai∩Aj|+...+(−1)^{n−1}×|A1∩A2∩...∩An| ...

  9. 重温C#中的值类型和引用类型

    在C#中,数据类型分为值类型和引用类型两种. 引用类型变量存储的是数据的引用,数据存储在数据堆中,而值类型变量直接存储数据.对于引用类型,两个变量可以引用同一个对象.因此,对一个变量的操作可能会影响另 ...

  10. Cilium系列-8-绕过 IPTables 连接跟踪

    系列文章 Cilium 系列文章 前言 将 Kubernetes 的 CNI 从其他组件切换为 Cilium, 已经可以有效地提升网络的性能. 但是通过对 Cilium 不同模式的切换/功能的启用, ...