搜狗编程题谁知道那个坑测试用例在哪里??一直80%

稍后贴代码.
全部评论
根据我多次测试,不同时间,评测姬性能差不少,可能你交的时候恰好评测姬抽了
点赞 回复 分享
发布于 2017-09-08 18:23
90%  调了一个小时   最后手机关机了  电脑没网了  血崩!!!
点赞 回复 分享
发布于 2017-09-08 18:10
#include<iostream> #include<cmath> #include<algorithm> #include<vector> using namespace std; int main() { int n; cin >> n; vector<double> a(n); cin >> a[0]; bool flag = 0; double du = a[0] + 180; int index; for (int i = 1; i < n; i++) { scanf("%lf", &a[i]); //cin >> a[i]; 这里只能通过60% if (flag) continue; if (a[i] > du) { flag = 1; index = i; } } if (flag == 0) { printf("%.8f", a[n - 1] - a[0]); return 0; } double res = a[index-1] - a[0]; int j = index; for (int i = 0; i < index; i++) { if (j == n - 1) { double tmp = a[j] - a[i]; if (tmp > 180) tmp = 360 - tmp; res = max(res, tmp); } else { double tmp = a[j] - a[i], tr = tmp; while (tmp <= 180 && j<n - 1) { tr = tmp; j++; tmp = a[j] - a[i]; } if(tmp>180) tmp = 360 - tmp; if (tr > 180) tr = 360 - tr; tr = max(tr, tmp); if (tr > res) res = tr; } } res = max(res, a[n - 1] - a[index]); printf("%.8f", res); return 0; } 复杂度O(n)
点赞 回复 分享
发布于 2017-09-08 18:10
思路,二分查找。复杂度,O(NlogN) #include <cstdio> #include <algorithm> using namespace std; int main(){ int n; scanf("%d",&n); double res = 0; double a[n]; for(int i=0;i<n;++i){ scanf("%lf",&a[i]); } for(int i=0;i<n;++i){ if(a[i]<180){ double tem = a[i]+180; if(tem>=360) tem -= 360; auto it = upper_bound(a,a+n,tem); int loc = it-a; if(loc==n){ res = max(res,a[n-1]-a[i]); }else{ res = max(res,360-a[loc]+a[i]); if(loc-1>0){ res = max(res,a[loc-1]-a[i]); } } }else{ double tem = a[i] -180; auto it = upper_bound(a,a+n,tem); int loc = it-a; res = max(res,a[i]-a[loc]); if(loc>0){ res = max(res,a[loc-1]+360-a[i]); }else if(loc==0){ res = max(a[n-1]-a[i],res); } } } printf("%.8lf\n",res); }
点赞 回复 分享
发布于 2017-09-08 18:07
使用二分查找,,,每次查找degre[i]+180最近的数,即为隔i点最远的点
点赞 回复 分享
发布于 2017-09-08 18:06
过了90% 应该还可以优化,没时间了。。
点赞 回复 分享
发布于 2017-09-08 18:05
双指针,70%,gg
点赞 回复 分享
发布于 2017-09-08 18:04
//只过了80% #include <iostream> #include <vector> using namespace std; int main(){ int n; double tmp; while(cin>>n){ vector<double> vec; for(int i=0;i<n;i++){ cin>>tmp; vec.push_back(tmp); } double max=0,temp; int flag=0; for(int i=0;i<n;i++){ int begin=i,end=n-1,mid; if(vec[end]-vec[begin]<=180.0){ temp=vec[end]-vec[begin]; break; } else{ while(begin+1<end){ mid=(begin+end+1)/2; temp=vec[mid]-vec[i]; if(temp==180){ flag=1; } else if(temp<180.0){ begin=mid; } else{ end=mid; temp=360.0-temp; } if(max<temp) max=temp; if(flag) break; } if(flag) break; } } if(max<temp) max=temp; printf("%.8lf\n",max); } }
点赞 回复 分享
发布于 2017-09-08 18:04
大佬晚点贴,30以后再贴,我以前贴了代码。然后有那种晚考15分钟的人,***,还可以贴我的代码,然后我三题Ac都没有过,,,
点赞 回复 分享
发布于 2017-09-08 18:04
io上面
点赞 回复 分享
发布于 2017-09-08 18:03
同80
点赞 回复 分享
发布于 2017-09-08 18:02
考完了,贴一下呗
点赞 回复 分享
发布于 2017-09-08 18:01
圆那道题吗
点赞 回复 分享
发布于 2017-09-08 18:00

相关推荐

牛客848095834号:举报了
点赞 评论 收藏
分享
LemontreeN:有的兄弟有的我今天一天面了五场,4个二面一个hr面
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务