关注
代码很烂,将就看吧;
两个数组分别存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); }
}
}
查看原帖
点赞 评论
相关推荐
03-05 20:42
门头沟学院 Java 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 我的实习日记 #
3695527次浏览 31909人参与
# 你认为小厂实习有用吗? #
126624次浏览 693人参与
# 你收到了哪些公司的笔试? #
2933次浏览 13人参与
# 滴滴笔试 #
37543次浏览 213人参与
# 你现在的工作,是“成长”还是“消耗”? #
2391次浏览 49人参与
# 在国企工作的人,躺平了吗? #
405434次浏览 3969人参与
# 实习进度记录 #
1217841次浏览 11839人参与
# 你上一次加班是什么时候? #
139627次浏览 780人参与
# 金三银四,你的春招进行到哪个阶段了? #
19371次浏览 263人参与
# 字节跳动笔试 #
79539次浏览 367人参与
# 小米编程考试 #
32863次浏览 156人参与
# 2025,我想...... #
92014次浏览 675人参与
# 秋招报数:你投了多少家公司? #
157400次浏览 960人参与
# 金融银行面经 #
101458次浏览 551人参与
# 美团笔试 #
708103次浏览 4687人参与
# AI岗位暴涨12倍,你会转AI赛道吗? #
7493次浏览 142人参与
# 你听到的“最没用”的秋招建议 #
54029次浏览 326人参与
# 职场上哪些行为很加分? #
338754次浏览 3768人参与
# 拼多多集团-PDD笔试 #
12160次浏览 143人参与
# 27届实习投递记录 #
1505次浏览 29人参与
