ural1097 Square Country 2

Source: Internet
Author: User
Tags gcd

Square Country 2Time limit:1.0 Second
Memory limit:64 mbthe Square Parliament of the square country (recall the corresponding problem from the USU 2001 persona L contest) has decreed, the national Square Park is created. Of course, the Park should occupy a large square. Unfortunately, at the moment a lot of square citizens has invested (with the help of last Championship ' s participants) th Eir quadrics into the "so" a part of the country is already occupied. It's now impossible to find a land for the Park without affecting interests of the private owners. Thus Some of the pieces of land must is expropriated. To avoid social unrest the Parliament have to locate the Park so, the interests of as less important as possible citize NS were affected. It is better to expropriate land from a thousand of simple citizens than from one member of the Parliament or from one ban K-owner. The occupied pieces of land is marked with numbers from 1 to according to importance of the owner. Pieces of landBelonging to Honest Tax-payers was marked with number 1, the land belonging to the members of the Parliament was marked with 98 , possessions of great businessmen was marked with a, and the property of the square president was marked with 100.InputTh E first line contains the number  L, which is the length of a side of the Square country (in meters), and the number A, which is the length of a side of the Park (1≤ AL≤10000). The next line contains the number M(1≤ M≤100) of occupied pieces of land (according to the square rules A-piece of land are a square with integer coordinates of c Orners and its sides is parallel to the axes). The next MLines contain information about these pieces of land:importance of the owner, length of the square ' s side and the Coordin Ates of the lower left corner, which is integers from 1 to L  (the coordinates of the lower left corner of the Square country itself is). Each of the piece of land are contained in the country and may intersect another piece of land only along its boundary. Note that land marked with number 1 (that's importance 1) is not a mentioned in the list altogether. Besides, some pieces of land belong to the members of [not Square] jury who helped to formulate the previous problem. This are marked with number 255 and cannot are expropriated at all. Outputyou should output the least possible importance of land which must is expropriated (a number from 1 to) or the W Ord impossible if it is impossible to create the Park does involving land of importance more than 100. The number and area of expropriated pieces is not important. You should to importance of the most important of the affected land-owners. Sample
input Output
5 3694 2 4 13 1 1 12 1 1 22 2 2 1100 1 2 4255 1 5 5
3

Analysis: Reference http://blog.csdn.net/jyysc2010/article/details/9968813;

Violent enumeration of rectangle vertices can be, complexity O (M3);

But the perception of data is slightly problematic;

Code:

#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineVI vector<int>#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)#definePII pair<int,int>#defineLson L, Mid, rt<<1#defineRson mid+1, R, rt<<1|1Const intmaxn=1e2+Ten;using namespacestd;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q) {ll F=1; while(q) {if(q&1) f=f*p;p=p*p;q>>=1;}returnF;}intn,m,k,t,b[maxn],c[maxn],ans,p,q;structnode{intid,x,y,z; Node () {} node (int_ID,int_z,int_x,int_y) {ID=_id,x=_x,y=_y,z=_z; }}A[MAXN];intMain () {inti,j; Ans= +; scanf ("%d%d%d",&n,&m,&k); Rep (I,1, K) {        intb,c,d,e; scanf ("%d%d%d%d",&b,&c,&d,&e); A[i]=node (b,c,d,e); } a[0]=node (0,1,0,0); Rep (I,0, K) Rep (J,0, K) {        intx=a[i].x+a[i].z,y=a[j].y+a[j].z,now=1; if(x+m-1>n| | y+m-1>n)Continue; Rep (T,1, K) {            if(a[t].x>x+m-1|| a[t].y>y+m-1|| a[t].x+a[t].z-1<x| | a[t].y+a[t].z-1<y)Continue; now=Max (now,a[t].id); } ans=min (ans,now); }    if(ans<= -) printf ("%d\n", ans); ElsePuts"Impossible"); //System ("Pause");    return 0;}

ural1097 Square Country 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.