CF#267 (Div. 2) A

来源:互联网 发布:图片装饰软件 编辑:程序博客网 时间:2024/05/16 19:31
A. George and Accommodation
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
题目链接:http://codeforces.com/contest/467/problem/A
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行给出房间现住人数和房间容量,如果二者差大于等于2,那么二人便可以入住,求能够入住的房间数量。

完整代码:

#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    int n;    while(~scanf("%d",&n))    {        int p , q , cnt = 0;        for(int i = 0 ; i < n ; i ++)        {            scanf("%d%d",&p,&q);            if(q - p >= 2)                cnt ++;        }        printf("%d\n",cnt);    }}





0 0
原创粉丝点击