2024 CCPC 哈尔滨站(哈尔滨)VP
赛时情况
VP 时间:2026.11.18 17:40-21:46
| 解题数 | 总用时 | 解出题目 | 排名/总人数 | 比例 |
|---|---|---|---|---|
| 5 | 633 | CGJKM |
137/280(铜牌) | 48.9% |
C. 在哈尔滨指路(0:16,spq)
转换后操作变成 \(2n-1\) 步,写一个函数改一下相对方向即可。
#include<bits/stdc++.h>
#define Std_Maker lhm
#define ll long long
using namespace std;
ll t,n,a[101];
char op[101];
char change(char now,char tar)
{
if(now=='N')
{
if(tar=='W') return 'L';
if(tar=='E') return 'R';
}
else if(now=='E')
{
if(tar=='N') return 'L';
if(tar=='S') return 'R';
}
else if(now=='S')
{
if(tar=='W') return 'R';
if(tar=='E') return 'L';
}
else if(now=='W')
{
if(tar=='N') return 'R';
if(tar=='S') return 'L';
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++) cin>>op[i]>>a[i];
cout<<2*n-1<<" "<<op[1]<<endl<<"Z "<<a[1]<<endl;
for(int i=2;i<=n;i++) cout<<change(op[i-1],op[i])<<endl<<"Z "<<a[i]<<endl;
}
return 0;
}
M. 奇怪的上取整(0:27,lhm)
根据题里给出的伪代码跑一遍即可发现规律,做一个 \(O(\sqrt{n})\) 的因数分解存到一个 vector 里,排序后按顺序模拟求和即可。
#include<bits/stdc++.h>
#define Std_Maker lhm
#define ll long long
using namespace std;
ll t,n,cnt;
vector<ll> v;
ll calc(ll x)
{
v.clear();
cnt=0;
for(int i=1;i*i<=x;i++)
{
if(x%i==0)
{
v.push_back(i);
v.push_back(x/i);
cnt+=2;
}
}
sort(v.begin(),v.end());
ll ans=0;
for(int i=1;i<cnt;i++) ans+=(v[i]-v[i-1])*(x/v[i-1]);
return ans+1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--)
{
cin>>n;
cout<<calc(n)<<endl;
}
return 0;
}

浙公网安备 33010602011771号