hdu 3262 09 宁波 现场 C - Seat taking up is tough 暴力 难度:0
Description
It will have very bad effect when such subjects occur on the BBS.
So, we urgently need a seat-taking-up rule. After several days of argument, the rule finally comes out:
As shown in the figure below, the seats in a classroom form a n×m grid( n rows and m columns), and every cell in the grid represents a seat. The coordinates of the seat in the north-west corner are (1,1) and the coordinates of the seat in the south-east corner seat are (n,m). As you know, some seats make you feel good and some seats don’t. So every seat has a “feeling index”.
Students can take up seats for himself and his friends. Of course, if a seat is already taken up by a student, it can’t be taken up by others.
For the convenience of communication between friends, when a student is trying to take up seats, he wants all the seats he needs to be consecutive and in the same row. If he can do that, he takes up all the seats he needs, and save the most western one for himself. For example, if a student wants to take up 3 seats, then taking (2,2),(2,3),(2,4) and saving (2,2) for himself is ok; but taking (2,2),(2,4),(2,5) is invalid because those seats are not consecutive. Under the precondition of accomplishing his seat-taking job, a student always wants the “feeling index” of his seat to be as large as possible.
However, if a student cannot take up all the seats he needs, he will just try to take up only one seat for himself because he doesn’t want to get into the trouble of explaining “Why they can get seats but I can’t?” to some of his friends. Of course he still wants the “feeling index” of his seat to be as large as possible in that situation.
Everyone wants to know where are the seats he can take up .This problem seems a little bit complicated for them. So they want you to write a program to solve the problem.
Input
For each test case:
The first line contains three integers: n , m and k ( 1 <= n,m<=30, 1<=k<=50). It means that there are n rows of seats in the classroom and there are m seats in every row. k is the number of students who come into the classroom trying to take up seats.
Following are n lines describing the seats by north to south order .Each line represents a row of seats and contains m integers, indicating the “feeling index” of every seat in that row, by west to east order. “Feeling index” can be fit in a 32-bit integer.
Then k lines follow (We call them k “student lines”). Each line is in the format of “hh:mm q” ( 0 <= hh < 24, 0 <=mm <= 59, 1<=q<=50 ) meaning that a student comes into the classroom at mm minutes past hh o’clock, trying to take up q seats. mm and hh are all two digit integers with possible leading zero, and q is also an integer. Please note that when a student enters the class room, he begins to do his seat taking job immediately and the job takes no time.
It is guaranteed that the “feeling index” of every seat is different and no students come into the classroom at the same time.
Output
Sample Input
11 12 15 14 13
21 22 25 24 23
16 17 20 19 18
6 7 10 8 9
1 2 5 4 3
09:00 2
09:01 5
09:02 5
09:03 5
09:04 5
09:05 3
09:06 2
09:07 3
0 0 0
Sample Output
3 1
1 1
4 1
5 1
2 5
2 1
-1
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std; const int maxn=40;
const int maxq=60; int graph[maxn][maxn];
bool flag[maxn][maxn];
int n,m,k; struct quest
{
int time,num,q;
int x,y;
} P[maxq]; bool cmp1(quest A,quest B)
{
return A.time<B.time;
}
bool cmp2(quest A,quest B)
{
return A.num<B.num;
} void solve(quest &kk)
{
int ax,ay,sx,sy,cnt;
ax=ay=sx=sy=-1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(flag[i][j]) continue;
cnt=0;
if((ax==-1&&ay==-1)||(graph[i][j]>graph[ax][ay])){
ax=i; ay=j;
}
for(int k=j;k<m;k++){
if(flag[i][k]) break;
else cnt++;
}
if(cnt>=kk.q){
if((sx==-1&&sy==-1)||(graph[i][j]>graph[sx][sy])){
sx=i; sy=j;
}
}
}
}
if(sx==-1&&sy==-1){
kk.x=ax;
kk.y=ay;
if(kk.x!=-1) flag[kk.x][kk.y]=1;
}
else{
kk.x=sx;
kk.y=sy;
for(int i=0;i<kk.q;i++) flag[kk.x][kk.y+i]=1;
}
} int main()
{
char cc[20];
int tt,num1,num2,ll;
while(scanf("%d%d%d",&n,&m,&k),n!=0||m!=0||k!=0){
for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&graph[i][j]);
memset(flag,0,sizeof(flag));
for(int i=0;i<k;i++){
scanf("%s %d",cc,&tt);
P[i].num=i;
P[i].q=tt;
ll=strlen(cc);
if(cc[2]==':'){
num1=((cc[0]-'0')*10+(cc[1]-'0'))*60;
if(ll-3>=2) num2=(cc[3]-'0')*10+(cc[4]-'0');
else num2=cc[3]-'0';
}
else{
num1=(cc[0]-'0')*60;
if(ll-2>=2) num2=(cc[2]-'0')*10+(cc[3]-'0');
else num2=cc[2]-'0';
}
P[i].time=num1+num2;
}
sort(P,P+k,cmp1);
for(int i=0;i<k;i++) solve(P[i]);
sort(P,P+k,cmp2);
for(int i=0;i<k;i++){
if(P[i].x==-1) printf("-1\n");
else printf("%d %d\n",P[i].x+1,P[i].y+1);
}
}
return 0;
}
hdu 3262 09 宁波 现场 C - Seat taking up is tough 暴力 难度:0的更多相关文章
- hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分 圆相交面积 难度:1
Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...
- hdu 3268 09 宁波 现场 I - Columbus’s bargain 读题 最短路 难度:1
Description On the evening of 3 August 1492, Christopher Columbus departed from Palos de la Frontera ...
- hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度:1
F - Computer Virus on Planet Pandora Time Limit:2000MS Memory Limit:128000KB 64bit IO Format ...
- hdu 3689 杭州 10 现场 J - Infinite monkey theorem 概率dp kmp 难度:1
J - Infinite monkey theorem Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &am ...
- hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0
Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...
- hdu 4771 13 杭州 现场 B - Stealing Harry Potter's Precious 暴力bfs 难度:0
Description Harry Potter has some precious. For example, his invisible robe, his wand and his owl. W ...
- HDU 3262 Seat taking up is tough (模拟搜索)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3262 题意:教室有n*m个座位,每个座位有一个舒适值,有K个学生在不同时间段进来,要占t个座位,必须是连 ...
- HDU 3262/POJ 3829 Seat taking up is tough(模拟+搜索)(2009 Asia Ningbo Regional)
Description Students often have problems taking up seats. When two students want the same seat, a qu ...
- hdu 5078 2014鞍山现场赛 水题
http://acm.hdu.edu.cn/showproblem.php?pid=5078 现场最水的一道题 连排序都不用,由于说了ti<ti+1 //#pragma comment(link ...
随机推荐
- LAMP开发(1)
apache web服务器软件,最近款的有7兆大小,工作:监听端口,接收请求,解析HTTP协议,转发给PHP比如:当一个客户端的请求发过来的时候,通常客户端(浏览器),请求发送给某一台IP,这个IP肯 ...
- hive引入jar包--HIVE.AUX.JARS.PATH和hive.aux.jars.path
hive需要引入包时?该怎么引入? 一.hive-site.xml中的hive.aux.jars.path 此配置项对于hive server有效,但是是不会作用到hive shell.也就是说即使你 ...
- 【Python】获取翻页之后的各页面中的属性值。
如何获取翻页之后的页面中的html标签中的属性值? # coding=utf-8 from selenium import webdriver if __name__=="__main__& ...
- PhotoSwipe中文API(一)
入门 您应知道之前先做起事情: 1. PhotoSwipe不是一个简单的jQuery插件,至少基本的JavaScript知识才能安装. 2. PhotoSwipe需要预定义的图像尺寸(更多关于这一点) ...
- SaltStack系列(二)之常用模块
一.saltstack的内置模块汇总 acl, aliases, alternatives, apache, archive, artifactory, block ...
- C#让应用程序只运行一个实例的几种方法
一 判断是否有相同的实例已经运行 1 根据“Mutex”判断是否有相同的实例在运行 /// <returns>已有实例运行返回true,否则为false</returns>pu ...
- bat笔记
背景介绍 现入职的公司包含发送EDM的项目,每天都有各种题型邮件需要发送,但是由于各种原因,发送EDM程序的服务器老是被网管各种重启 :) 作为负责人,对这事很恼火,隔几天就被投诉,怎么又没收到考勤邮 ...
- 026-B树(一)
1.内节点:非根非叶子节点,即非根的分支节点. 2.名称:B-树=B树=平衡多路查找树. 3.定义:m阶B树. (0).根节点孩子数rootChildNum范围:若没有孩子节点则孩子数为0,若有孩子则 ...
- 20154312曾林 - Exp1 PC平台逆向破解
1.逆向及Bof基础实践说明 1.1-实践目标 对象:pwn1(linux可执行文件) 目标:使程序执行另一个代码片段:getshell 内容: 手工修改可执行文件,改变程序执行流程,直接跳转到get ...
- 20155207 2016-2017-2 《Java程序设计》第八周学习总结
20155207 2016-2017-2 <Java程序设计>第八周学习总结 教材学习内容总结 第15章 通用API 15.1 日志 15.1.1 日志API简介 java.util.lo ...