搜狗编程题谁知道那个坑测试用例在哪里??一直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

相关推荐

今年读完研的我无房无车无对象,月入还没有过万&nbsp;看到他在朋友圈晒房产证,感叹自己白读了这么多年书
梦想是成为七海千秋:那咋了,双9毕业的现在还没存款呢(因为没念完),高中毕业的去直播带货月入几百万也是完全有可能的,退一万步讲,有些人刚出生父母就给买车买房了,上哪说理去,哪怕是同一个起点也会有截然不同的走向,过好自己的生活就完事了。
点赞 评论 收藏
分享
我就是0offer糕手:北大不乱杀
点赞 评论 收藏
分享
程序员牛肉:主要是因为小厂的资金本来就很吃紧,所以更喜欢有实习经历的同学。来了就能上手。 而大厂因为钱多,实习生一天三四百的就不算事。所以愿意培养你,在面试的时候也就不在乎你有没有实习(除非是同级别大厂的实习。) 按照你的简历来看,同质化太严重了。项目也很烂大街。 要么换项目,要么考研。 你现在选择工作的话,前景不是很好了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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