题解:P12947 [GCJ Farewell Round #1] Illumination Optimization
4041nofoundGeoge · · 题解
水题。出题人你是不是有病,还要输出第几行。
题目大意
O 让你在
思路
考虑贪心。
最开始照亮的地方是
证明:
设全长为
代码
#include<bits/stdc++.h>
using namespace std;
int x[100005];
int main(){
int t;
cin>>t;
int q=t;
while(t--){//我偏不用for循环
int m,r,n;
cin>>m>>r>>n;
for(int i=1;i<=n;i++){
cin>>x[i];
}
int i=1;
int pos=0;
int maxn=-1;
int res=0;
bool poss=true;
while(pos<m){
maxn=-1;
while(i<=n&&x[i]-r<=pos){
maxn=x[i],i++;
}
if(maxn==-1){
poss=false;
break;
}
res++;
pos=maxn+r;
if(pos>=m)break;
if(i>n||x[i]-r>pos){
poss=false;
break;
}
}
cout<<"Case #"<<q-t<<": ";
if(poss)cout<<res;
else cout<<"IMPOSSIBLE";
cout<<"\n";
}
return 0;
}