这是一个简单的模拟问题,可以通过以下步骤解决:
- 关键发现:对于每个帖子,只需要判断 统计满足条件的帖子数量即可
- 解题策略:读入每个帖子的点赞数和反对数判断是否满足 的条件累计满足条件的帖子数量
- 具体步骤:读入 和 遍历每个帖子判断条件并计数
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = sc.nextInt(); int ans = 0; for(int i = 0; i < n; i++) { int a = sc.nextInt(); int b = sc.nextInt(); if(Math.abs(a - b) >= x) { ans++; } } System.out.println(ans); } }