记录详情

Accepted

/in/foo.cc: In function 'bool judge(int)':
/in/foo.cc:7:10: warning: unused variable 'i' [-Wunused-variable]
  int t=0,i=0,c=0;
          ^
/in/foo.cc: In function 'int main()':
/in/foo.cc:37:8: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout<<ans<<endl;
        ^~~
# 状态 耗时 内存占用
#1 Accepted 1ms 192.0 KiB
#2 Accepted 1ms 208.0 KiB
#3 Accepted 1ms 200.0 KiB
#4 Accepted 1ms 212.0 KiB
#5 Accepted 1ms 200.0 KiB
#6 Accepted 22ms 504.0 KiB
#7 Accepted 22ms 504.0 KiB
#8 Accepted 25ms 496.0 KiB
#9 Accepted 25ms 504.0 KiB
#10 Accepted 22ms 460.0 KiB

代码

#include<iostream>
using namespace std;
int a[50010];
int n,d,m;
bool judge(int x)
{
	int t=0,i=0,c=0;
	for(int i=1;i<=n+1;i++)
	{
	 if(a[i]-a[c]<x)
	 t++;
	 else
	 c=i;	
	}
	if(t>m)return false;
	else return true;
}
int main()
{
	cin>>d>>n>>m;
	int ans;
	for(int i=1;i<=n;i++)
	 cin>>a[i];
	a[n+1]=d; 
	 int l=0,r=d,mid;
	while(l<=r) 
	{
	 mid=(l+r)/2;
	 if(judge(mid))
	 {
	  l=mid+1;
	  ans=mid;
	 }
	 else
	 r=mid-1; 	
	}
	cout<<ans<<endl;
	return 0; 
}

信息

递交者
类型
递交
题目
P1055 跳石头
比赛
随机真题赛第四轮(xhy&lfy讲题)
题目数据
下载
语言
C++
递交时间
2019-11-13 13:26:38
评测时间
2019-11-13 13:26:38
评测机
分数
100
总耗时
125ms
峰值内存
504.0 KiB