2024长春全国邀请赛CCPC
文章目录
- G - Platform Game
- I - The Easiest Problem
- L - Recharge
G - Platform Game
题目来源:G - Platform Game
解题思路
可以先对每个平台的高度从大到小排序,高度相同再根据横坐标从左往右排序,依次遍历每个平台,如果高度在当前点的位置下面并且平台范围包含点的横坐标,则更新高度和坐标点。
代码实现
#include<bits/stdc++.h>
#define int long long
#define PII pair<int,int>
#define fi first
#define se second
#define endl '\n'
using namespace std;
const int N=1e6;
int n,a,b;
struct po
{int x,y,z;
}p[N];
int cmp(po a,po b)//先排高度再排x
{if(a.z==b.z )return a.x <b.x ;return a.z>b.z;
}
void solve()
{cin>>n;for(int i=1;i<=n;i++)cin>>p[i].x >>p[i].y >>p[i].z ;cin>>a>>b;sort(p+1,p+1+n,cmp);int h=b,ans=a;for(int i=1;i<=n;i++){if(p[i].z<h&&ans>p[i].x &&ans<p[i].y ){h=p[i].z ;ans=p[i].y ;}}cout<<ans<<endl;return ;
}
signed main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int _=1;cin>>_;while(_--)solve();return 0;}
I - The Easiest Problem
输出21
略
L - Recharge
题目来源:L - Recharge
解题思路
分奇偶讨论,代码很详细。
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{int k,x,y;cin>>k>>x>>y;if(k%2==0)cout<<(y*2+x)/k<<endl;//是偶数的话直接除以kde else{if(k==1)//如果是1特判掉,数量为x+y {cout<<x+y<<endl;return ;}int n=k/2;int m=y/n;//大房间有多少能构成多少k,后面还要用小房间凑 if(x>=m)//如果x给大房间凑后还有剩余 {int sum=m;//先将大房间构造的记录下来 int z=y%n;//剩余的大房间的个数 x-=m;//小房间被用去凑的剪掉 x+=2*z;//剩余的小房间和大房间能量条总和 cout<<sum+x/k<<endl; // 输出总的 }else//否则 {int sum=x;//最多能构造x个 int z=y-x*n;//大房间减去用去构造的剩余的 cout<<sum+z/(n+1)<<endl;;}}
}
signed main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int t=1;cin >> t;while(t--) solve();return 0;}