码迷,mamicode.com
首页 > 其他好文 > 详细

Distribution(F题)---第八届河南省程序设计大赛

时间:2015-05-16 23:11:41      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

Description

One day , Wang and Dong in the Dubai desert expedition, discovered an ancient castle. Fortunately, they found a map of the castle.The map marks the location of treasures.

They agreed to distribute the treasures according to the following rules:

Wang draws a horizontal line on the map and then Dong draws a vertical one so that the map is divided into 4 parts, as show below.   

II                              I

 

 

III                             IV

 

 

Wang will save the treasures in I and III ,while those situated in II and IV will be taken away by Dong. Wang first draw a horizontal line, Dong after the draw a vertical line.

They drew several pairs of  lines. For each pair, Wang wants to know the difference between their treasures.

It‘s guaranteed that all the reasures will lie on neither of the lines drew by them.

 

Input

One day , Wang and Dong in the Dubai desert expedition, discovered an ancient castle. Fortunately, they found a map of the castle.The map marks the location of treasures.

They agreed to distribute the treasures according to the following rules:

Wang draws a horizontal line on the map and then Dong draws a vertical one so that the map is divided into 4 parts, as show below.   

II                              I

 

 

III                             IV

 

 

Wang will save the treasures in I and III ,while those situated in II and IV will be taken away by Dong. Wang first draw a horizontal line, Dong after the draw a vertical line.

They drew several pairs of  lines. For each pair, Wang wants to know the difference between their treasures.

It‘s guaranteed that all the reasures will lie on neither of the lines drew by them.

 

Output

Output  contains   lines , a single line with a integer , the difference described above.

Sample Input

10 3
29 22
17 14
18 23
3 15
6 28
30 27
4 1
26 7
8 0
11 21
2 25
5 10
19 24

Sample Output

-6
4
4

这一题当时是第一个做的,并且一血使我们学校的一个队拿的,应该是道签到题吧

题意:给你n个点代表treasure的位置,然后再给你m个点,每给一个点时,都已这个点画一个十字架,其中位于第一部分和第三部分的是Wang的treasure共有p个,第二部分和第四部分是Dong的

共有q个,最终求他俩的差值即p-q;

#include<iostream>
#include<stdio.h>
#include<algorithm>
#define N 1100
using namespace std;
struct node
{
    int x,y;
};
int main()
{
    int n,m,i,j,x,y,p,q;
    node a[N];
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&a[i].x,&a[i].y);
        }
        for(i=0;i<m;i++)
        {
            p=q=0;
            scanf("%d%d",&x,&y);
            for(j=0;j<n;j++)
            {
                if((a[j].x>x&&a[j].y>y)||(a[j].x<x&&a[j].y<y))//Wang的点的个数
                    p++;
                else
                    q++;Dong的点的个数
            }
            printf("%d\n",p-q);
        }
    }
    return 0;
}

 

Distribution(F题)---第八届河南省程序设计大赛

标签:

原文地址:http://www.cnblogs.com/zhengguiping--9876/p/4508732.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!