UVA10963 The Swallowing Ground【水题】

Now that the wicked is punished, there is still work to do. For example, the ground needs to seal itself up. (Otherwise, good people will accidentally fall into Hell, which is not good.)
    The ground swallowed Don Giovanni by collapsing: Part of the ground collapsed–fell off to Hell–and this created a gap that swallowed Don Giovanni. The only way the ground can be fixed is by sliding landmasses to close up the gap. Here is an example. The left diagram shows the ground with a ravine. Assume that the ground extends infinitely to the north and to the south, and there are seams on the east and west ends; so the northern block can slide southward, and the southern block can slide northward. The right diagram shows the gap closed.
在这里插入图片描述
    Here is another example. The ravine in the left diagram cannot be closed perfectly by sliding the ground northward and southward. The right diagram shows the result of the best effort: there is still a hole.
在这里插入图片描述
    Write a program to determine if the gap can be closed. The ground is a grid with rows (a row runs east-west) and columns (a column runs north-south). Holes are cells on the grid, and the gap consists of holes.
Input
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.
    The first line contains the number of columns W of the ground to be considered. Then W lines follow, specifying the boundary of the gap by columns: a line represents a column, and the order of the lines follows the east-to-west order. Each line contains y1, the north-most row of the gap in this column, and y2, the south-most row of the gap in this column. Row numbers are integers between -100 and 100 inclusive.
    The input specifies a valid gap: the holes separate the ground into exactly a northern block and a southern block. There are no holes embedded inside a block. There are no islands.
Note: The sample input below corresponds to the first diagram.
Output
For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.
    Output the line
yes
if the gap can be closed by sliding blocks north and south; and
no
otherwise.
Sample Input
1
5
2 1
0 -1
1 0
1 0
2 1
Sample Output
yes

问题链接UVA10963 The Swallowing Ground
问题简述:(略)
问题分析
    。
    简单题不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10963 The Swallowing Ground */

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t, n;
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);
        int a, b, d, ans = 1;
        if(n) {
            scanf("%d%d", &a, &b);
            d = a - b;
            for (int i = 1; i < n ; i++) {
                scanf("%d%d", &a, &b);
                if (a - b != d)
                    ans = 0;
            }
        }

        if(ans) printf("yes\n");
        else printf("no\n");
        if(t) printf("\n");
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值