Codeforces Round #267 (Div. 2) A. George and Accommodation

George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.

George and Alex want to live in the same room. The dormitory has
n rooms in total. At the moment the i-th room has
pi people living in it and the room can accommodate
qi people in total (pi?≤?qi). Your task is to count
how many rooms has free place for both George and Alex.

Input

The first line contains a single integer n
(1?≤?n?≤?100) — the number of rooms.

The i-th of the next
n lines contains two integers pi and
qi
(0?≤?pi?≤?qi?≤?100) — the number of people who already live in the
i-th room and the room‘s capacity.

Output

Print a single integer — the number of rooms where George and Alex can move in.

Sample test(s)

Input

3
1 1
2 2
3 3

Output

0

Input

3
1 10
0 10
10 10

Output

2
题意:有n个寝室,一共可以住qi,已经住了pi个,问再来两个可以住进去几个寝室
思路:直接计算的大水题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	int p, q, ans = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &q, &p);
		if (p - q >= 2)
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

时间: 2024-10-05 05:41:49

Codeforces Round #267 (Div. 2) A. George and Accommodation的相关文章

Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the follow

01背包 Codeforces Round #267 (Div. 2) C. George and Job

题目传送门 1 /* 2 题意:选择k个m长的区间,使得总和最大 3 01背包:dp[i][j] 表示在i的位置选或不选[i-m+1, i]这个区间,当它是第j个区间. 4 01背包思想,状态转移方程:dp[i][j] = max (dp[i-1][j], dp[i-m][j-1] + sum[i] - sum[i-m]); 5 在两个for循环,每一次dp[i][j]的值都要更新 6 */ 7 #include <cstdio> 8 #include <cstring> 9 #i

Codeforces Round #267 (Div. 2) C. George and Job

The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work. Given a sequence of n integers p

Codeforces Round #267 (Div. 2) C. George and Job (dp)

wa哭了,,t哭了,,还是看了题解... 8170436                 2014-10-11 06:41:51     njczy2010     C - George and Job             GNU C++     Accepted 109 ms 196172 KB 8170430                 2014-10-11 06:39:47     njczy2010     C - George and Job             GNU C

Codeforces Round #267 (Div. 2)

A.George and Accommodation 题意:给定数组a,b,问b-a>=2有多少个 思路:直接模拟.. B.Fedor and New Game 题意:给定m+1个n位以内的二进制数,求前m个有多少个跟第m+1的二进制下不同位数不超过k的个数 思路:直接模拟 C.George and Job 题意:给定n个数,求k个的段,每段有m个连续得数,使得和最大 思路:直接dp,注意long long不会超内存 1 /* 2 * Author: Yzcstc 3 * Created Tim

Codeforces Round #267 (Div. 2) A

题目: A. George and Accommodation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Al

Codeforces Round #267 (Div. 2) solution

A.George and Accommodation 题目大意:给你n个宿舍的可以容纳的人数和现在已住的人数,问有几个宿舍可以安排两个人进去住. 解法:模拟,无trick. 代码: 1 #include <cstdio> 2 3 int main() { 4 int n; 5 while(scanf("%d", &n) != EOF){ 6 int a, b, ans = 0; 7 for(int i = 0; i < n; i++) { 8 scanf(&q

Codeforces Round #227 (Div. 2)---E. George and Cards(贪心, 树状数组+set维护, 好题!)

George is a cat, so he loves playing very much. Vitaly put n cards in a row in front of George. Each card has one integer written on it. All cards had distinct numbers written on them. Let's number the cards from the left to the right with integers f

Codeforces Round #267 (Div. 2) B. Fedor and New Game

After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game ?Call of Soldiers 3?. The game has (m?+?1) players and n types of soldiers in total. Players ?Call of Soldiers 3? are numbered for