The 2023 ICPC Asia Taoyuan Regional Programming Contest(A~D,F,H,L~M)组队训练题解

news/2025/3/6 8:32:11/文章来源:https://www.cnblogs.com/cjcf/p/18754145

比赛链接:https://codeforces.com/gym/105544
这次是赛时8题

A.Counterfeit Money

#include<bits/stdc++.h>
#define endl '\n'using namespace std;
typedef long long ll;const int INF=0x3f3f3f3f;
const int N=2e5+5;ll t,n,m;void fio(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}void solve(){string str;cin >> str;n=str.length();ll ttt=(3-n%3)%3;for(int i=1; i<=ttt; i++){str='0'+str;}n=str.length();//cout << str << endl;ll op=1;ll ans=0;for(int i=n-3; i>=0; i-=3){string tmp=str.substr(i,3);//cout << tmp << endl;ll tt=0;for(auto j:tmp){tt*=10;tt+=j-'0';}if(op){ans+=tt;op^=1;}else{ans-=tt;op^=1;}}ans=llabs(ans);cout << ans << " ";if(ans%13==0){cout << "YES" << endl;}else cout << "NO" << endl;}signed main()
{fio();cin >> t;//t=1;while(t--){solve();}return 0;
}

B.Recurring Decimal to Fractions

#include<bits/stdc++.h>
#define endl '\n'using namespace std;
typedef long long ll;const int INF=0x3f3f3f3f;
const int N=2e5+5;ll t,n,m;ll ksm(ll x, ll y)
{ll ans = 1;while (y){if (y & 1){ans = ans*x;}x = x*x;y >>= 1;}return ans;
}ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}void fio(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}void solve(){ll a,b;ll num1,num2;cin >> a >> b >> num1 >> num2;ll fenzi=num2, fenmu=(ksm(10,b)-1)*ksm(10,a);ll tmp=gcd(fenmu,fenzi);fenmu/=tmp,fenzi/=tmp;//cout << fenzi << " " << fenmu << endl;fenzi=fenzi*ksm(10,a)+fenmu*num1;fenmu*=ksm(10,a);tmp=gcd(fenzi,fenmu);fenmu/=tmp,fenzi/=tmp;cout << fenzi << " " << fenmu << endl;
}signed main()
{fio();cin >> t;//t=1;while(t--){solve();}return 0;
}

C.Where the Lantern Lights are Dimming

#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll                                  long long 
#define lowbit(x) (x & -x)
#define endl "\n"//                           交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
struct tree
{ll l, r, o, ot, v, vt;ll gs;ll ys;ll sum;
}p[1000005 << 2];
vector<pair<ll, ll>>a(1000005);//0~n-1
void push_up(ll i)
{p[i].v = p[i << 1].v + p[i << 1 | 1].v;p[i].sum = p[i << 1].sum + p[i << 1 | 1].sum;p[i].gs = p[i << 1].gs + p[i << 1 | 1].gs;p[i].ys= p[i << 1].ys + p[i << 1 | 1].ys;return;
}
void build(ll i, ll l, ll r)
{p[i].l = l, p[i].r = r;if (l == r){p[i].o = a[l].first;p[i].ys=0;p[i].gs = 0;p[i].ot = 0;if (p[i].o==1)p[i].v = a[l].second, p[i].gs = 1;else if(p[i].o==-1)p[i].ys=1;p[i].sum = a[l].second;return;}build(i << 1, l, l + r >> 1);build(i << 1 | 1, (l + r >> 1) + 1, r);push_up(i);return;
};
void push_down(ll i)
{if (p[i].ot){p[i << 1].v = p[i << 1].sum - p[i << 1].v;p[i << 1 | 1].v = p[i << 1 | 1].sum - p[i << 1 | 1].v;p[i << 1].gs = p[i << 1].r - p[i << 1].l + 1 -p[i<<1].ys- p[i << 1].gs;p[i << 1 | 1].gs = (p[i << 1 | 1].r - p[i << 1 | 1].l + 1)-p[i<<1|1].ys - p[i << 1 | 1].gs;p[i << 1].ot ^= 1;p[i << 1 | 1].ot ^= 1;p[i].ot = 0;}return;
}
void u1(ll i, ll l, ll r)//异或
{if (p[i].l == l && p[i].r == r){p[i].ot ^= 1;p[i].gs = p[i].r - p[i].l + 1-p[i].ys - p[i].gs;//个数p[i].v = p[i].sum - p[i].v;return;}push_down(i);ll mid = (p[i].l + p[i].r) >> 1;if (l <= mid)u1(i << 1, l, min(r, mid));if (r >= mid + 1)u1(i << 1 | 1, max(l, mid + 1), r);push_up(i);
}
ll q(ll i, ll l, ll r)
{ll ans = 0;if (p[i].l == l && p[i].r == r){ans += p[i].sum;return ans;}push_down(i);ll mid = (p[i].l + p[i].r) >> 1;if (l <= mid)ans += q(i << 1, l, min(r, mid));if (r >= mid + 1)ans += q(i << 1 | 1, max(l, mid + 1), r);return ans;
}
bool vis[1000002];
int main()
{fio();ll n,m;cin >> n >> m;ll ans = 0;ll an = 0;ll cnt = 0;for (ll i = 1; i <= n; i++){ll l, r;cin >> l >> r;if (l == -1){vis[i - 1] = 1;cnt++;ans += r;}a[i - 1] = { l,r };}if (cnt == -1)//全坏灯{cout << ans << endl;return 0;}build(1, 0, n - 1);while (m--){char x;cin >> x;if (x == 'W'){ll l, r;cin >> l >> r;u1(1, l, r);}else{ll l;cin >> l;an += p[1].gs * l;}}for (ll i = 0; i < n; i++){ll f = q(1, i, i);if (vis[i])continue;else an += a[i].second;}an += ans;cout << an << endl;
}

D. Quarantine Policy

#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll                                  long long 
#define lowbit(x) (x & -x)
#define endl "\n"//                           交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
ll ksm(ll x, ll y)
{ll ans = 1;while (y){if (y & 1){ans = ans*x%mod;}x = x*x % mod;y >>= 1;}return ans % mod ;
}
ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
struct s
{ll l, r;ll id;double f;friend bool operator<(const s& a, const s& b){if(fabs(a.f-b.f)<1e-9)return a.id<b.id;else return a.f> b.f;}
}p[2500];
ll a[333][330];
ll o[5]={1,0,-1,0};
ll e[5]={0,1,0,-1};
ll f1[5]={1,-1,1,-1};
ll f2[5]={1,-1,-1,1};
int main()
{fio();ll t;cin>>t;ll cs=0;while(t--){cs++;ll n,m;ll l,r;cin>>n>>m>>l>>r;string f[250];for(ll i=1;i<=n;i++)cin>>f[i],f[i]='0'+f[i];for(ll i=1;i<=n;i++){for(ll j=1;j<=m;j++)a[i][j]=0;}for(ll i=1;i<=n;i++){for(ll j=1;j<=m;j++){if(f[i][j]=='V'){for(ll k=0;k<=3;k++){ll nx=i+o[k];ll ny=j+e[k];if(nx<1||nx>n||ny<1||ny>m)continue;a[nx][ny]=l;}for(ll k=0;k<=3;k++){ll nx=i+f1[k];ll ny=j+f2[k];if(nx<1||nx>n||ny<1||ny>m)continue;a[nx][ny]=max(a[nx][ny],r);}}}}cout<<"Airplane"<<" "<<"#"<<cs<<":"<<endl;for(ll i=1;i<=n;i++){for(ll j=1;j<=m;j++){if(f[i][j]=='V')cout<<"V";else cout<<a[i][j];}cout<<endl;}cout<<endl;}
}      

F.Baker's Dilemma

#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll                                  long long 
#define lowbit(x) (x & -x)
#define endl "\n"//                           交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
ll ksm(ll x, ll y)
{ll ans = 1;while (y){if (y & 1){ans = ans*x%mod;}x = x*x % mod;y >>= 1;}return ans % mod ;
}
ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
struct s
{ll l, r;ll id;double f;friend bool operator<(const s& a, const s& b){if(fabs(a.f-b.f)<1e-9)return a.id<b.id;else return a.f> b.f;}
}p[2500];
int main()
{fio();ll t;cin>>t;while (t--){	ll n;cin>>n;for(ll i=1;i<=n;i++){ll l,r;cin>>l>>r;p[i].l=l,p[i].r=r;p[i].id=i;p[i].f=(double)p[i].r/p[i].l;}sort(p+1,p+1+n);for(ll i=1;i<=n;i++){cout<<p[i].id<<" ";}cout<<endl;}
}      

H.Bank Deposit Challenge

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int value[N];
int wei[N];
int dp[2000][150] = { 0 };
void solve() {int c;cin >> c;int x = 0;char n;int w = 0;int cnt = 0;n = getchar();while (1) {n = getchar();if (n == '\n') {if (cnt == 0) {value[++x] = w;}else {wei[++x] = w;}cnt++;if (cnt == 2) {break;}w = 0;if (cnt == 1) {x = 0;}continue;}if (n == ' ') {if (cnt == 0) {value[++x] = w;}else {wei[++x] = w;}w = 0;continue;}w = w * 10 + (n - '0');}for (int i = 1; i <= x; i++) {for (int j = c; j >= 0; j--) {//如果是01背包倒序遍历容量,无限个则正序遍历容量if (j < wei[i]) {dp[j][i] = dp[j][i - 1];//如果放不进来记得直接顺延}else {dp[j][i] = max(dp[j][i - 1], (dp[j - wei[i]][i - 1] + value[i]));}}}printf("%d", dp[c][x]);}
int main() {int t = 1;//	scanf("%d",&t);while (t--) {solve();printf("\n");}return 0;
}
//2963628

L.Nine Never

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
void solve(){ll n;scanf("%lld",&n);if(n<9){printf("%lld",n);return ;}else{if(n%2==0){printf("%lld",(n/2)%mod);}else{if(n==11){printf("4");}else if(n==13){printf("5");}else if(n==15){printf("6");}else if(n==17){printf("8");}else if(n==19){printf("9");}else if(n==21){printf("9");}else if(n==23){printf("9");}else if(n==25){printf("9");}else if(n==27){printf("9");}else{printf("%lld",((n-11)/2+1)%mod);}}}}
int main(){int t=1;
//	scanf("%d",&t);while(t--){solve();printf("\n");}return 0;
}
//2963628

M.Task scheduler

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;struct node{int id;int tim;int va;
}a[N];
bool cmp(node x,node y){if(x.va!=y.va){return x.va<y.va;}return x.tim<y.tim;
}
void solve(){int n;scanf("%d",&n);for(int i=1;i<=n;i++){a[i].tim=i;scanf("%d",&a[i].id);}for(int i=1;i<=n;i++){scanf("%d",&a[i].va);}sort(a+1,a+1+n,cmp);for(int i=1;i<=n;i++){if(i>1)printf(" ");printf("%d",a[i].id);}
}
int main(){int t;scanf("%d",&t);while(t--){solve();printf("\n");}return 0;
}
//2963628

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/894482.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

从零开始在Springboot+Vue项目上搭建Nginx服务器,完成静态文件存放到本地电脑上。

一、事情的起因: 写管理系统的时候,数据表中有一个字段被用来存储上传图片的地址。本人在上传图片的时候,采用模拟上传操作,将照片存储到了本地电脑的D盘上。存放在数据表中字段的值为D:/uploads/1741141288982_bd8415d7a452957780e0193a075fedc.png。其中D:/uploads,是本…

【设计模式】从零开始,用原型模式简化你的Java对象创建过程!

概述 用一个已经创建的实例作为原型,通过复制该原型对象来创建一个和原型对象相同的新对象。 结构 原型模式包含如下角色:抽象原型类:规定了具体原型对象必须实现的的 clone() 方法。具体原型类:实现抽象原型类的 clone() 方法,它是可被复制的对象。访问类:使用具体原型类…

SWPU CTF 2023 秋季新生赛 If_else

题干 访问首页,源码如下 <?php $a=false; $b=false; if(你提交的部分将会被写至这里) {$a=true;} else {$b=true;} if($a===true&&$b===true) eval(system(cat /flag)); ?>分析源码发现,通过post方式传递check参数,如果该值既满足true又满足f…

**20242802 2024-2025-2 《网络攻防实践》第一周作业**

20242802 2024-2025-2 《网络攻防实践》第一周作业 1.知识点梳理与总结 1.1 相关知识点与总结 因为在本课之前我没有学习过网络攻防的相关知识,在第一次实验前我先阅读了课程资料中第0章和第1章的内容结合网络资料,我对本门课程有了大致的理解:学习网络攻防知识作为网络安全…

20242924 《网络攻防实践》第1周作业

20242924 任雯楚《网络攻防实践》 第1周作业 1.知识点梳理与总结 1.1 VMware Workstation 多系统并行运行:在单台物理机上同时部署多个虚拟机(如 Kali 攻击机、Metasploitable 靶机),支持 Windows/Linux 等异构系统共存。 1.2 虚拟机镜像 虚拟机镜像是一种虚拟机的文件,它…

180多页详细解读多元化AI!清华大学《AIGC发展研究》

180多页详细解读多元化AI!清华大学《AIGC发展研究》无论是最初的ChatGPT还是目前大火的DeepSeek,底层都依赖于从于自然语言处理(NLP)、计算机视觉(CV)等先进的人工智能技术。无论是从最初的文本生成域到视频生成域以及现在逻辑推理领域都是从语料预训练→模型训练→参数学…

读DAMA数据管理知识体系指南11数据建模(下)

数据建模包括规范化、抽象化,规划成果,建立模型(含正向、逆向工程),涉及范式层次、抽象方法、图表定义、血缘追踪、持续改进及逻辑物理建模等。1. 规范化 1.1. 规范化(Normalization)是运用规则将复杂的业务转化为规范的数据结构的过程 1.2. 范式化的基本目标是保证每个属…

The Ethernaut题解

Level_0.Hello Ethernaut安装MetaMask; F12中的Console,一些指令查看state:查看自己的钱包地址->player:查看余额->getBalance(player):查看合约->ethernaut:合约交互,比如查看合约的owner->ethernaut.owner():从水龙头处获得ETH:(可以Sepolia PoW Faucet挖,也可以…

CAN通信

一.什么是CAN总线 1.CAN总线的概念CAN总线(Controller Area Network Bus)控制器局域网总线2.CAN总线的特点 3.常见通信协议对比(UART、IC、SPI、CAN)特性 UART IC SPI CAN全称 Universal Asynchronous Receiver/Transmitter Inter-Integrated Circuit Serial Peripheral In…

typora图床搭建+完美解决PicGo图片上传重命名问题

typora图床搭建+完美解决PicGo图片上传重命名问题typora图床搭建+完美解决PicGo图片上传重命名问题 typora设置上图中第五步需要你下载PicGo应用并安装 PicGo配置 下载安装好后得到如图界面这时需要对该软件进行配置 文档在这里https://picgo.github.io/PicGo-Doc/zh/guide/con…

[NSSCTF 2022 Spring Recruit]ezgame(两种解法)

可以看到,这个题目一打开就是一道简单的小游戏,玩了一会没看到什么提示就打开页面源码看看有没有提示可以看到只要分数超过65就会告诉你flag,但是真的自己去玩基本上是玩不到65分的,于是我尝试修改页面代码看能不能绕过 解法1 由于页面爆炸了,这里就不附上截图,反正修改分…

【转载】VPS、ECS、Docker和k8s

图片及内容均来源于小林coding公众号:面试官:Docker 和 k8s 之间是什么关系? 物理服务器 一台看得见摸得着的机器,其实就是云厂商页面里提到的物理服务器或物理机。不同厂商叫法不同,有的厂商叫它独立服务器。 vps 和 ecs VPS(Virtual Private Server,虚拟专用服务器)。…