😥
A. Parallel Projection
因为路径是与坐标轴平行的,所以可以看出只有四条可能的路径(前后左右),都算一遍取最小即可.
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
int w,d,h;
cin>>w>>d>>h;
int a,b,f,g;
cin>>a>>b>>f>>g;
int ans1=abs(f-a)+h+min(b+g,2*d-b-g);
int ans2=abs(b-g)+h+min(a+f,2*w-a-f);
cout<<min(ans1,ans2)<<'\n';
}
return 0;
}B. Going to the Cinema
可以感觉出来需要排序,先把
若
特别地,若
枚举一下即可
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int a[N];
int main() {
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+1+n);
a[n+1]=1e9;
int ans=0;
int t=1;
if(a[1]!=0) //判一下是否可能全不去
ans++;
while(t<=n)
{
while(a[t]>=t)
t=a[t]+1;
while(a[t]<t)
t++;
ans++;
}
cout<<ans<<'\n';
}
return 0;
}