トヨタ自動車プログラミングコンテスト2024#7(ABC 362)
非常好名次,使我的
四发罚时应该是这次比赛最唐的东西了,没有就进前一千了
A.Buy a Pen
特判秒了,懒得打三种 ans=,所以就把不能选的那个赋值成无穷大了
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(false);
#define tests int cases;cin>>cases;while(cases--)
int main(){
speed
int a,b,c;
cin>>a>>b>>c;
string x;
cin>>x;
if(x=="Red") a=101;
if(x=="Green") b=101;
if(x=="Blue") c=101;
cout<<min({a,b,c})<<endl;
}
B.Right Triangle
讲个好玩的,这个题需要求两点
dis[1]=sqrt(x[1]*x[1]+y[1]*y[1]);
后面求勾股定理的时候发现好像不对,这好像是勾股定理,所以改成下面这样:
dis[1]=sqrt((x[1]-x[2])*(y[1]-y[2]));
这玩意 re 了,我也没干别的,唯一想到的就是给负数开根了,一看果然是负的...
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(false);
#define tests int cases;cin>>cases;while(cases--)
const double eps=1e-8;
int main(){
speed
int x[4],y[4];
cin>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3];
double dis[4];
dis[1]=sqrt((x[1]-x[2])*(x[1]-x[2])+(y[1]-y[2])*(y[1]-y[2]));
dis[2]=sqrt((x[2]-x[3])*(x[2]-x[3])+(y[2]-y[3])*(y[2]-y[3]));
dis[3]=sqrt((x[3]-x[1])*(x[3]-x[1])+(y[3]-y[1])*(y[3]-y[1]));
// cout<<dis[1]<<" "<<dis[2]<<" "<<dis[3]<<endl;
if(dis[3]<dis[1]) swap(dis[3],dis[1]);
if(dis[3]<dis[2]) swap(dis[3],dis[2]);
if(abs(dis[1]*dis[1]+dis[2]*dis[2]-dis[3]*dis[3])<=eps) cout<<"Yes"<<endl;
else cout<<"No"<<endl;'
}
还有一个就是 eps 的问题,这个题刻意卡了直接判等,handmade 测试点会全 WA,不过我恰好改一次都改对了,所以没吃第二发罚时
C.Sum = 0
稍微有点意思,首先算出所有左边界的和,再算出所有右边界的和,注意到左边界一定是最小的和,而右边界一定是最大的,因此有解的充要条件应为
然后就再扫一遍,从最大的和中减掉(每次都改一个右边界为左边界),如果当前最大和减不动了,那就把它减到
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(false);
#define tests int cases;cin>>cases;while(cases--)
const double eps=1e-8;
#define int long long
int n;
int l[200001],r[200001];
int maxn,minn;
signed main(){
speed cin>>n;
for(int i=1;i<=n;++i){
cin>>l[i]>>r[i];
maxn+=r[i];
minn+=l[i];
}
if(maxn<0 or minn>0){
cout<<"No"<<endl;
return 0;
}
cout<<"Yes"<<endl;
for(int i=1;i<=n;++i){
if(maxn>0){
if(maxn>=(r[i]-l[i])){
maxn-=r[i]-l[i];
cout<<l[i]<<" ";
}
else{
cout<<r[i]-maxn<<" ";
maxn=0;
}
}
else if(maxn==0){
cout<<r[i]<<" ";
}
}
}
D.Shortest Path 3
DIJ 版本的考试题,和我考试打的那份错解一个思路
#include<bits/stdc++.h>
using namespace std;
#define int long long
int cnt;
int n,m,x;
int a[500000];
struct shabicth{
int q,dat;
bool operator < (const shabicth &a) const{
return dat>a.dat;
}
};
struct node{
int to,w,next;
}edge[600000];
int head[200010];
bool f[200100];
int dis[200010];
int sum[2000];
int sbcth[7000][3];
void add(int u,int v,int w){
edge[++cnt].next=head[u];
edge[cnt].to=v;
edge[cnt].w=w;
head[u]=cnt;
}
void dij(int s){
priority_queue<shabicth> qq;
int x,y;
shabicth cc;
cc.q=s;
cc.dat=a[s];
qq.push(cc);
memset(dis,0x7f,sizeof(dis));
memset(f,0,sizeof(f));
dis[s]=a[s];
while(!qq.empty()){
x=qq.top().q;
y=qq.top().dat;
qq.pop();
if(!f[x]){
f[x]=true;
for(int i=head[x];i;i=edge[i].next){
cc.q=edge[i].to;
if(!f[cc.q]&&dis[cc.q]>y+edge[i].w+a[cc.q]){
dis[cc.q]=y+edge[i].w+a[cc.q];
cc.dat=dis[cc.q];
qq.push(cc);
}
}
}
}
}
signed main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
dis[i]=a[i];
}
for(int i=1;i<=m;i++){
int x,y,num;
cin>>x>>y>>num;
add(x,y,num);
add(y,x,num);
}
dij(1);
for(int i=2;i<=n;i++) cout<<dis[i]<<' ';
}
E.Count Arithmetic Subsequences
窝太菜辽,想了半条才明白 Arithmetic Subsequences 是等差数列的意思
日文阅读理解
上の解法は更に高速化することができます.以下の状態を持つ DP を考えます.
公差
または,各
没用翻译读懂了,大概就是开一个 DP 记录出项,长度,公差三个参数,这样就能唯一确定一个等差数列,再用 map 判重.
赛时差不多打出来了,因为这个题
此外
G.Count Substring Query
没想到考了 AC 自动机板子题,板子不会打就偷了一份
后记
谴责一款强迫我看日文题解的网站
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!