路过这座城市 level
获赞
5
粉丝
2
关注
20
看过 TA
2
上海大学
2021
Java
IP属地:北京
暂未填写个人简介
私信
关注
2020-09-17 10:59
已编辑
上海大学 Java
做完出来,刷牛客,发现3道编程都是广联达之前笔试的原题。。。   第一道长草ac   第二道元素91%,超时   第三道范围攻击81%,有错误,想知道第三道哪里没考虑到,求指点   import java.util.Scanner; import java.util.TreeMap; public class Main {     public static void main(String[] args) {    &nbs...
响当当的名字z:lz这个解法确实有点点毛病 可以使用滑动窗口做,AC,时间复杂度O(n) 我用C++写的,可以看下 #include<bits/stdc++.h> using namespace std; struct master{ int pos; int hp; master(int _pos,int _hp){ pos=_pos; hp=_hp; } }; bool cmp(master a,master b){ return a.pos<b.pos; } vector<master>v; int main() { int n,y; cin>>n>>y; for(int i=0;i<n;i++){ int x,h; cin>>x>>h; v.push_back(master(x,h)); } sort(v.begin(),v.end(),cmp); int size=2*y; int l=0; int r=0; int ans=0; while(l<n){ while(r+1<n && v[r+1].pos-v[l].pos <= size) r++; ans+=v[l].hp; for(int i=r;i>=l;i--) v[i].hp-=v[l].hp; while(l<n && v[l].hp<=0) l++; } cout<<ans; return 0; }
投递广联达等公司10个岗位
0 点赞 评论 收藏
分享

创作者周榜

更多
关注他的用户也关注了:
牛客网
牛客网在线编程
牛客网题解
牛客企业服务