关注
代码很烂,将就看吧;
两个数组分别存x和y坐标,将x坐标排序,两个map存x对应的序号,每次都从拍好序的x往后面倒,如果倒下的牌的范围比当前范围大,则替换当前范围
import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Demo23 { public static void main(String[] args) {
Scanner in=new Scanner(System.in); int n=in.nextInt(); int a[]=new int[n+1]; int b[]=new int[n+1]; Map<Integer,Integer>map=new HashMap<Integer, Integer>(n); Map<Integer,Integer>map1=new HashMap<Integer, Integer>(n); for (int i = 1; i < n+1; i++) { int test=in.nextInt(); a[i]=test; int test1=in.nextInt(); b[i]=test1; map.put(i,test); map1.put(test,i); }
Arrays.sort(a); for (int i = 1; i <n+1 ; i++) { int x=map.get(i); int flag=0; for (int j =1; j < n+1; j++) { if (a[j]==x){
flag=j; break; }
} int y=b[i]; int temp=0; temp=x+y-1; int num=0; while (flag<n+1){ if (flag==n) { break; } else { if (a[flag+1]>=x+1&&a[flag+1]<=temp){
num++; if (a[flag+1]+b[map1.get(map.get(flag))+1]-1>temp)temp=a[flag+1]+b[map1.get(map.get(flag))+1]-1; }
}
flag++; }
System.out.println(num+1); }
}
}
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享


腾讯
| 实习
| 41个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 如何KTV领导 #
32938次浏览 284人参与
# 你投递的公司有几家约面了? #
39493次浏览 236人参与
# 掌阅春招 #
89733次浏览 523人参与
# 研究所笔面经互助 #
55306次浏览 395人参与
# 软开人,秋招你打算投哪些公司呢 #
67448次浏览 725人参与
# vivo求职进展汇总 #
168153次浏览 1022人参与
# 生物制药/化工校招攻略 #
33980次浏览 265人参与
# 你遇到过哪些神仙同事 #
45719次浏览 471人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
73441次浏览 543人参与
# 硬件/芯片公司工作体验 #
58725次浏览 560人参与
# 如何缓解入职前的焦虑 #
142171次浏览 1129人参与
# TP-LINK工作体验 #
38706次浏览 787人参与
# Tplink求职进展汇总 #
102526次浏览 570人参与
# 在职场上,你最讨厌什么样的同事 #
10833次浏览 139人参与
# 你最近一次加班是什么时候? #
32333次浏览 252人参与
# 考研人,我有话说 #
17520次浏览 342人参与
# 软件开发春招备战日记 #
58147次浏览 499人参与
# 秋招白月光 #
53336次浏览 786人参与
# 产品每日一题 #
29289次浏览 408人参与
# 过年最难忘的一件事 #
10956次浏览 155人参与
# 你今年的平均薪资是多少? #
94549次浏览 462人参与