A题:https://codeforces.com/contest/1293/problem/A
题意:有一个食堂,共n层,但是有k层关闭了,现在A在第s层,问A至少爬几层楼梯可以吃饭。
思路:这道题的话,用set做一下就行。
AC代码:
#include <bits/stdc++.h>
typedef long long ll;
const int maxx=10010;
const int inf=0x3f3f3f3f;
using namespace std;
int main()
{
int t;
cin>>t;
set<int>st;
while(t--)
{
st.clear();
int n,s,k;
cin>>n>>s>>k;
while(k--)
{
int a;
cin>>a;
st.insert(a);
}
int ans=0;
while((st.count(s+ans) || s+ans>n) && (st.count(s-ans) || s-ans<=0))
ans++;
cout<<ans<<endl;
}
return 0;
}
B题:https://codeforces.com/contest/1293/problem/B
题意:J有s个对手,每个问题可以有t个人回答错误,他便可获得t/s的收益,问J的最大收益是多少。
思路:这道题的话,贪心,每次淘汰一人赚的更多。
AC代码:
#include <bits/stdc++.h>
typedef long long ll;
const int maxx=10010;
const int inf=0x3f3f3f3f;
using namespace std;
int main()
{
int n;
cin>>n;
double ans=0;
for(int i=1; i<=n; i++)
ans+=1.0/(double)i;
cout<<fixed<<setprecision(12)<<ans<<endl;
return 0;
}
C题:https://codeforces.com/contest/1293/problem/C
题意:有一个2*n的矩阵,初始时每一个矩阵中每一个方格都是可通过的,然后有q个询问,每次给出一个方格的坐标,使得这个方格的状态翻转(通过变不通过或者不通过变通过),对于每个查询问你是否可以从(1,1)到(2,n)。
思路:这道题的话,每个岩浆点的对面或斜对面如果也有岩浆点,那么这两点之间就会形成障碍,统计这种障碍的数量即可。
AC代码:
#include <bits/stdc++.h>
typedef long long ll;
const int maxx=100010;
const int inf=0x3f3f3f3f;
using namespace std;
int a[5][maxx];
int n,q,k,x,y;
int main()
{
cin>>n>>q;
while(q--)
{
cin>>x>>y;
x--;
if(a[x][y]==0)
{
a[x][y]=1;
for(int i=-1; i<=1; i++)
{
if(a[1-x][y+i]==1)
k++;
}
}
else
{
a[x][y]=0;
for(int i=-1; i<=1; i++)
{
if(a[1-x][y+i]==1)
k--;
}
}
if(!k)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
D题:https://codeforces.com/contest/1293/problem/D
题意:给定x0,y0,ax,ay,bx,by,一堆数据点:(x0,y0),(x1,y1) = (ax* x0+bx,ay*y0+by),起点(xs,ys),时间t,走一步都需要1单位时间,t时间内,从起点出发最多可以收集多少个数据点。
思路:这道题的话,分析点集的特点,可以知道每一个数据点都在下标比它小的数据点的右上方,而且离下一个数据点的距离大于离第0个数据点的距离。枚举Aroma从哪个点出发;先往第0个数据点走,然后尽可能往右上走。
AC代码:
#include <bits/stdc++.h>
typedef long long ll;
const int maxx=100010;
const int inf=0x3f3f3f3f;
using namespace std;
ll a0, b0, ax, bx, ay, by;
ll xs, ys, t;
ll dx[maxx], dy[maxx];
ll dis[maxx];
int res;
int main()
{
cin>>a0>>b0>>ax>>ay>>bx>>by;
cin>>xs>>ys>>t;
ll tx=a0, ty=b0;
int top;
for(top=0; tx<=2e16 && ty<=2e16; top++)
{
dx[top]=tx;
dy[top]=ty;
tx=tx*ax+bx;
ty=ty*ay+by;
}
for(int i=1; i<=top-1; i++)
dis[i]=dx[i]-dx[0]+dy[i]-dy[0];
for(int i=0; i<=top-1; i++)
{
ll tmp=t-abs(xs-dx[i])-abs(ys-dy[i]);
if (tmp<0)
continue;
int tot=0;
if (tmp<=dis[i])
{
tot=i-(lower_bound(dis,dis+top,dis[i]-tmp)-dis)+1;
}
else
{
tot=upper_bound(dis+i+1,dis+top,tmp-dis[i])-dis;
}
res=max(res,tot);
}
cout<<res<<endl;
}