Solution Set -「ABC 192」
「ABC 113A」Star
Link.
略。
#include<cstdio>
int x;
int main()
{
scanf("%d",&x);
for(int i=1;;++i)
{
if((x+i)%100==0)
{
printf("%d\n",i);
break;
}
}
return 0;
}
「ABC 192B」uNrEaDaBlE sTrInG
Link.
略。
#include<cstdio>
#include<cstring>
char s[1010];
int main()
{
scanf("%s",s+1);
bool flag=1;
int n=strlen(s+1);
for(int i=1;i<=n;++i)
{
if(i&1)
{
if(s[i]<'a'||s[i]>'z')
{
flag=0;
break;
}
}
else
{
if(s[i]<'A'||s[i]>'Z')
{
flag=0;
break;
}
}
}
printf("%s\n",flag?"Yes":"No");
return 0;
}
「ABC 192C」Kaprekar Number
Link.
照题意模拟。
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
long long las,now,n;
int k;
long long f(long long x)
{
long long one=0,ano=0;
vector<long long> num;
while(x>0)
{
num.push_back(x%10);
x/=10;
}
sort(num.begin(),num.end(),greater<long long>());
for(auto val:num) one=one*10+val;
reverse(num.begin(),num.end());
for(auto val:num) ano=ano*10+val;
// printf("%lld %lld\n",one,ano);
return one-ano;
}
int main()
{
scanf("%lld %d",&n,&k);
las=n;
if(k==0) return printf("%lld\n",n)&0;
while(k--)
{
now=f(las);
las=now;
}
printf("%lld\n",now);
return 0;
}
「ABC 192D」Base n
Link.
显然随着进制增大数字也会增大,所以可以二分。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
struct bigInt : vector<long long>{
bigInt &check( ){
while( ! empty( ) && ! back( ) ) pop_back( );
if( empty( ) ) return *this;
for( unsigned i = 1; i < size( ); ++ i ){ ( *this )[i] += ( *this )[i - 1] / 10; ( *this )[i - 1] %= 10; }
while( back( ) >= 10 ){ push_back( back( ) / 10 ); ( *this )[size( ) - 2] %= 10; }
return *this;
}
bigInt( long long tpN = 0 ){ push_back( tpN ); check( ); }
};
istream &operator >> ( istream &is, bigInt &tpN ){
string s;
is >> s; tpN.clear( );
for( int i = s.size( ) - 1; i >= 0; --i ) tpN.push_back( s[i] - '0' );
return is;
}
ostream &operator << ( ostream &os, const bigInt &tpN ){
if( tpN.empty( ) ) os << 0;
for( int i = tpN.size( ) - 1; i >= 0; --i ) os << tpN[i];
return os;
}
bool operator != ( const bigInt &one, const bigInt &another ){
if( one.size( ) != another.size( ) ) return 1;
for( int i = one.size( ) - 1; i >= 0; --i ){
if( one[i] != another[i] ) return 1;
}
return 0;
}
bool operator == ( const bigInt &one, const bigInt &another ){
return ! ( one != another );
}
bool operator < ( const bigInt &one, const bigInt &another ){
if( one.size( ) != another.size( ) ) return one.size( ) < another.size( );
for( int i = one.size( ) - 1; i >= 0; --i ){
if( one[i] != another[i] ) return one[i] < another[i];
}
return 0;
}
bool operator > ( const bigInt &one, const bigInt &another ){ return another < one; }
bool operator <= ( const bigInt &one, const bigInt &another ){ return ! (one > another ); }
bool operator >= ( const bigInt &one, const bigInt &another ){ return ! (one < another ); }
bigInt &operator += ( bigInt &one, const bigInt &another ){
if( one.size( ) < another.size( ) ) one.resize(another.size( ) );
for( unsigned i = 0; i != another.size( ); ++ i ) one[i] += another[i];
return one.check( );
}
bigInt operator + ( bigInt one, const bigInt &another ){ return one += another; }
bigInt &operator -= ( bigInt &one, bigInt another ){
if( one < another ) swap( one, another );
for( unsigned i = 0; i != another.size( ); one[i] -= another[i], ++ i ){
if( one[i] < another[i] ){
unsigned j = i + 1;
while( ! one[j] ) ++ j;
while( j > i ){ -- one[j]; one[--j] += 10; }
}
}
return one.check( );
}
bigInt operator - ( bigInt one, const bigInt &another ){ return one -= another; }
bigInt operator * ( const bigInt &one, const bigInt &another ){
bigInt tpN;
tpN.assign( one.size( ) + another.size( ) - 1, 0 );
for( unsigned i = 0; i != one.size( ); ++ i ){
for( unsigned j = 0; j != another.size( ); ++ j ) tpN[i + j] += one[i] * another[j];
}
return tpN.check( );
}
bigInt &operator *= ( bigInt &one, const bigInt &another ){ return one = one * another; }
bigInt divMod( bigInt &one, const bigInt &another ){
bigInt ans;
for( int t = one.size( ) - another.size( ); one >= another; -- t ){
bigInt tpS;
tpS.assign( t + 1, 0 );
tpS.back( ) = 1;
bigInt tpM = another * tpS;
while( one >= tpM ){ one -= tpM; ans += tpS; }
}
return ans;
}
bigInt operator / ( bigInt one, const bigInt &another ){ return divMod(one, another ); }
bigInt &operator /= ( bigInt &one, const bigInt &another ){ return one = one / another; }
bigInt &operator %= ( bigInt &one, const bigInt &another ){ divMod( one, another ); return one; }
bigInt operator % ( bigInt one, const bigInt &another ){ return one %= another; }
char s[70];
int n,cntot;
bigInt m,num[70],mx;
bool check(bigInt bas)
{
bigInt res=0,sab=1;
for(int i=1;i<=cntot;++i)
{
res+=num[i]*sab;
sab*=bas;
if(res>m) return false;
}
return true;
}
int main()
{
cin>>(s+1)>>m;
n=strlen(s+1);
for(int i=n;i>=1;--i)
{
num[++cntot]=s[i]-'0';
mx=max(mx,num[cntot]);
}
if(cntot==1) cout<<(num[cntot]<=m)<<"\n";
else
{
// bigInt l=0,r=1e18,ans=0;
// while(l<=r)
// {
// bigInt mid=(l+r)/2;
// if(check(mid))
// {
// l=mid+1;
// ans=mid;
// }
// else r=mid-1;
// }
// bigInt l=mx,r=m+1;
// while(l+1<r)
// {
// bigInt mid=(l+r)/2;
// if(check(mid)) l=mid;
// else r=mid;
// }
bigInt l=mx+1,r=m+1,ans=mx;
while(l<=r)
{
bigInt mid=(l+r)/2;
if(check(mid)) l=mid+1,ans=mid;
else r=mid-1;
}
cout<<ans-mx<<"\n";
}
return 0;
}
「ABC 192E」Train
Link.
我也不知道我怎么过的,反正就是 Dijkstra 板子套上去后把 if(dis[y]>dis[x]+z) 改成了 if(dis[y]>get(dis[x],k)+z),其中 get(dis[x],k) 就是算下一班车来的时间加上 dis[x] 本身。
然后就莫名其妙过了,可能算个贪心?
#include<queue>
#include<cstdio>
using namespace std;
const long long INF=1e18;
priority_queue<pair<long long,long long>,vector<pair<long long,long long> >,greater<pair<long long,long long> > > q;
vector<pair<long long,pair<long long,long long> > > e[100010];
long long n,m,st,ed,dis[100010],vis[100010];
long long get(long long val,long long k)
{
if(val%k==0) return val;
else return val+k-(val%k);
}
void find()
{
for(long long i=1;i<=n;++i) dis[i]=INF;
dis[st]=0;
q.push(make_pair(dis[st],st));
while(!q.empty())
{
long long now=q.top().second;
q.pop();
if(!vis[now])
{
vis[now]=1;
for(long long i=0;i<e[now].size();++i)
{
long long y=e[now][i].first,w=e[now][i].second.first,k=e[now][i].second.second;
if(dis[y]>get(dis[now],k)+w)
{
dis[y]=get(dis[now],k)+w;
q.push(make_pair(dis[y],y));
}
}
}
}
}
int main()
{
scanf("%lld %lld %lld %lld",&n,&m,&st,&ed);
for(long long i=1;i<=m;++i)
{
long long u,v,w,k;
scanf("%lld %lld %lld %lld",&u,&v,&w,&k);
e[u].push_back(make_pair(v,make_pair(w,k)));
e[v].push_back(make_pair(u,make_pair(w,k)));
}
find();
printf("%lld\n",dis[ed]==INF?-1:dis[ed]);
return 0;
}
「ABC 192F」Potion
Link.
考虑枚举 \(k\),设 \(f_{i,j,c}\) 为前 \(i\) 位选了 \(j\) 个数 balabala。
我也不知道怎么 DP 的,可能是本能做出来的。
后面自己意会吧,反正也没难度了。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long n,x,a[110],f[110][110][110],ans=1145141919810233454;
int main()
{
scanf("%lld %lld",&n,&x);
for(int i=1;i<=n;++i) scanf("%lld",&a[i]);
for(int s=1;s<=n;++s)
{
memset(f,-0x3f,sizeof(f));
f[0][0][0]=0;
for(int i=1;i<=n;++i)
{
for(int j=1;j<=min(s,i);++j)
{
for(int k=0;k<n;++k) f[i][j][k]=max(f[i-1][j][k],f[i-1][j-1][((k-a[i])%s+s)%s]+a[i]);
}
}
if(f[n][s][x%s]>=0) ans=min(ans,(x-f[n][s][x%s])/s);
}
printf("%lld\n",ans);
return 0;
}
Solution Set -「ABC 192」的更多相关文章
- Solution Set -「ABC 217」
大家好屑兔子又来啦! [A - Lexicographic Order] 说个笑话,\(\color{black}{\text{W}}\color{red}{\text{alkingDead} ...
- Diary / Solution Set -「WC 2022」线上冬眠做噩梦
大概只有比较有意思又不过分超出能力范围的题叭. 可是兔子的"能力范围" \(=\varnothing\) qwq. 「CF 1267G」Game Relics 任意一个 ...
- 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 ...
- Solution -「ABC 219H」Candles
\(\mathcal{Description}\) Link. 有 \(n\) 支蜡烛,第 \(i\) 支的坐标为 \(x_i\),初始长度为 \(a_i\),每单位时间燃烧变短 \(1\) ...
- Solution -「ABC 215H」Cabbage Master
\(\mathcal{Description}\) Link. 有 \(n\) 种颜色的,第 \(i\) 种有 \(a_i\) 个,任意两球互不相同.还有 \(m\) 个盒子,每个盒子可以被放 ...
- Solution -「ABC 213G」Connectivity 2
\(\mathcal{Description}\) Link. 给定简单无向图 \(G=(V,E)\),点的编号从 \(1\) 到 \(|V|=n\).对于 \(k=2..n\),求 \(H= ...
- Solution -「ABC 213H」Stroll
\(\mathcal{Description}\) Link. 给定一个含 \(n\) 个结点 \(m\) 条边的简单无向图,每条边的边权是一个常数项为 \(0\) 的 \(T\) 次多项式, ...
- Solution -「ABC 217」题解
D - Cutting Woods 记录每一个切割点,每次求前驱后驱就好了,注意简单判断一下开闭区间. 考场上采用的 FHQ_Treap 无脑莽. #include <cstdio> #i ...
- 「ABC 249Ex」Dye Color
考虑停时定理. 初始势能为 \(\sum \Phi(cnt_i)\),末势能为 \(\Phi(n)\),我们希望构造这样一个 \(\Phi:Z\to Z\) 函数,使得每一次操作期望势能变化量为常数. ...
- Note -「Lagrange 插值」学习笔记
目录 问题引入 思考 Lagrange 插值法 插值过程 代码实现 实际应用 「洛谷 P4781」「模板」拉格朗日插值 「洛谷 P4463」calc 题意简述 数据规模 Solution Step 1 ...
随机推荐
- GTX.Zip:一款可以替代 gzip 的基因大数据压缩软件
今天给大家推荐一款基因大数据压缩的大杀器:GTX.Zip. GTX.Zip 这款软件是由曾在 2016 年 GCTA 风云挑战赛中的那匹黑马--人和未来生物科技有限公司开发的,而当时他们也是打破了基因 ...
- Dapr在Java中的实践 之 服务调用
服务调用 通过服务调用(Service-to-service Invocation),服务可以使用 gRPC 或 HTTP 这样的标准协议来发现并可靠地与其他服务通信. Dapr采用边车(Sideca ...
- 【Clickhouse】ReplaceingMergeTree引擎final实现合并去重探索
前言 在OLAP实践中,在有数据更新的场景中,比如存储订单数据,我们经常会用到ReplaceingMergeTree引擎来去重数据,以获取数据的最新状态.但是ReplaceingMergeTree引擎 ...
- 10.1. Java性能调优
Java性能调优是一个复杂且重要的主题,它涉及到了JVM.垃圾收集器.内存管理.多线程.代码优化等多个方面.在本节中,我们将对Java性能调优的基本概念和方法进行简要介绍. 10.1.1. 理解性能指 ...
- 记录部署Datax、Datax-web 过程碰到的问题
我的第一篇博客 datax在网络上部署的文档有很多,这里不重复阐述,只描述过程中碰到的些许问题,记录下来. 1. 1 ERROR RetryUtil - Exception when calling ...
- 浅析开源容器标准——OCI
1.导语 容器技术火起来了以后,Docker的容器镜像和容器运行时已然成为行业的标准.此后,为了推进容器生态的健康发展.在Linux基金会的主导下,Docker和各大云厂商Google, Amazon ...
- typescript的必要性及使用
1 前言 作为一个前端语言,Javascript从最初只是用来写页面,到如今的移动终端.后端服务.神经网络等等,它变得几乎无处不在.如此广阔的应用领域,对语言的安全性.健壮性以及可维护性都有了更高的要 ...
- PostgreSQL 12 文档: SQL 语法
SQL 命令 这部分包含PostgreSQL支持的SQL命令的参考信息.每条命令的标准符合和兼容的信息可以在相关的参考页中找到. 目录 ABORT - 中止当前事务 ALTER AGGREGATE ...
- 渲染路径 - Deferred Texturing
目录 Deferred Texturing 为什么需要 Deferred Texturing? 光栅化的 Helper Lane 开销 Draw Call 更容易合批 利用 V-Buffer 可以做更 ...
- Federated Learning004
联邦学习--笔记004 2023.03.13周一 快中期答辩了(3.20),最近甲流高发期 毕设期间,今天学习了联邦学习的一篇论文---Differentially Private Federated ...