HDU 3262 Seat taking up is tough (模拟搜索)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3262
题意:教室有n*m个座位,每个座位有一个舒适值,有K个学生在不同时间段进来,要占t个座位,必须是连续的并且自己坐在最左边,如果有多个的话,找最舒适的座位,如果没有连续t个,那么只给自己找个最舒适的位子,如果都满的话,输出-1.
题解:一个简单的搜索模拟,注意的是,要排序每个同学进来的时间,而且输出要按照给的顺序输出,被坑了几次,样例数据太弱了。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; #define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define sd1(a) scanf("%lf",&a)
#define sd2(a,b) scanf("%lf%lf",&a,&b)
#define ss1(s) scanf("%s",s)
#define pi1(a) printf("%d\n",a)
#define pi2(a,b) printf("%d %d\n",a,b)
#define mset(a,b) memset(a,b,sizeof(a))
#define forb(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i<=b;i++) typedef long long LL;
const int N=33;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-8; int n,m,k;
int xh[N][N]; struct xkn
{
int time,ren;
int i;
}p[55]; struct jilu
{
int x,y;
}o[55]; bool cmp(xkn a,xkn b)
{
return a.time<b.time;
} bool yes(int i,int j,int ren)
{
for(int k=0;k<ren;k++)
if(xh[i][j+k]==-1)
return false;
return true;
} void xiaohao(int ren,int t)
{
int flag1=-1,flag2=-1;
int Max1,Max2;
int x,y;
for(int i=0;i<n;i++)
for(int j=0;j<=m-ren;j++)
{
if(yes(i,j,ren))
{
if(flag1==-1)
{
flag1=1;
Max1=xh[i][j];
x=i; y=j;
}
else if(Max1<xh[i][j])
{
Max1=xh[i][j];
x=i; y=j;
}
}
}
if(flag1!=-1)
{
//pi2(x+1,y+1);
o[t].x=x+1; o[t].y=y+1;
for(int k=0;k<ren;k++)
xh[x][y+k]=-1;
return ;
} forb(i,0,n)
forb(j,0,m)
{
if(xh[i][j]!=-1)
{
if(flag2==-1)
{
flag2=1;
Max2=xh[i][j];
x=i; y=j;
}
else if(Max2<xh[i][j])
{
Max2=xh[i][j];
x=i; y=j;
}
}
}
if(flag2!=-1)
{
//pi2(x+1,y+1);
o[t].x=x+1; o[t].y=y+1;
xh[x][y]=-1;
return ;
}
o[t].x=-1; o[t].y=-1;
} int main()
{
// freopen("input.txt","r",stdin);
while(scanf("%d%d%d",&n,&m,&k)&&(n+m+k))
{
forb(i,0,n) forb(j,0,m) si1(xh[i][j]);
forb(i,0,k)
{
int a,b;
scanf("%d:%d %d",&a,&b,&p[i].ren);
p[i].time=a*60+b;
p[i].i=i;
}
sort(p,p+k,cmp);
forb(i,0,k)
{
xiaohao(p[i].ren,p[i].i);
}
forb(i,0,k)//必须按照开始的顺序输出
{
if(o[i].x==-1)
puts("-1");
else
pi2(o[i].x,o[i].y);
}
}
return 0;
}
HDU 3262 Seat taking up is tough (模拟搜索)的更多相关文章
- HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)
HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...
- 【LOJ6254】最优卡组 堆(模拟搜索)
[LOJ6254]最优卡组 题面 题解:常用的用堆模拟搜索套路(当然也可以二分).先将每个卡包里的卡从大到小排序,然后将所有卡包按(最大值-次大值)从小到大排序,并提前处理掉只有一张卡的卡包. 我们将 ...
- 【BZOJ4524】[Cqoi2016]伪光滑数 堆(模拟搜索)
[BZOJ4524][Cqoi2016]伪光滑数 Description 若一个大于1的整数M的质因数分解有k项,其最大的质因子为Ak,并且满足Ak^K<=N,Ak<128,我们就称整数M ...
- 【BZOJ4345】[POI2016]Korale 堆(模拟搜索)
[BZOJ4345][POI2016]Korale Description 有n个带标号的珠子,第i个珠子的价值为a[i].现在你可以选择若干个珠子组成项链(也可以一个都不选),项链的价值为所有珠子的 ...
- JavaScript在表格中模拟搜索多关键词搜索和筛选
模拟搜索需要实现以下功能: 1.用户的模糊搜索不区分大小写,需要小写字母匹配同样可以匹配到该字母的大写单词. 2.多关键词模糊搜索,假设用户关键词以空格分隔,在关键词不完整的情况下仍然可以匹配到包含该 ...
- 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 3262 09 宁波 现场 C - Seat taking up is tough 暴力 难度:0
Description Students often have problems taking up seats. When two students want the same seat, a qu ...
- POJ 3829 Seat taking up is tough(——只是题目很长的模拟)
题目链接: http://poj.org/problem?id=3829 题意描述: 输入矩阵的大小n和m,以及来占位置的人数k 输入n*m的教室座位矩阵,每个值表示该座位的满意度 输入每个人来占位置 ...
- hdu 2629 Identity Card (字符串解析模拟题)
这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...
随机推荐
- PHP5.4的变化关注---What has changed in PHP 5.4.x(转)
What has changed in PHP 5.4.x Most improvements in PHP 5.4.x have no impact on existing code. There ...
- passwd命令限制用户密码到期时间
1.passwd命令 [root@rhel7 skel]# passwd -n -w -x rusky Adjusting aging data for user rusky. passwd: Suc ...
- (转 飛雲若雪)ADO.NET
一.简单介绍ADO.NET System.Data:DataTable,DataSet,DataRow,DataColumn,DataRelation,Constraint System.Data.C ...
- 学习WCF(1)
1. 什么是WCF WCF是创建面向服务应用程序的一个框架,用WCF, 你可以发送异步消息. 一个服务的终结点可以是服务宿主在IIS上面,也可以是一个服务宿主在应用程序上面.一个终结点也可以是客户端的 ...
- Hyper-V的三种网卡
External ======= 虚拟机和物理网络.本地主机都能通信 Internal ======= 虚拟机之间互相通信,并且虚拟机能和本机通信 Private ======= 仅允许运行在这台物理 ...
- 方形布局SquareLayout
public class SquareLayout extends RelativeLayout { public SquareLayout(Context context, AttributeSet ...
- github修改自己的昵称
由于刚接触github,不会用,就随便写了个昵称,后来想改,却不知道从哪里改,到百度搜结果都是说不能修改的(这里就不吐槽百度了),还是直接上图吧. 点击Settings,然后跳转到下面界面,点击Acc ...
- 三维FEM的刚度矩阵数量级
刚刚在调试三维的FEM代码,随手把全局刚度矩阵在FULL的情况下保存到了dat文件里. 注意,这个仅仅是一个半径为十的球的刚度矩阵 居然3.6G!!吓坏了!!截个图,留个纪念.还是老老实实用spars ...
- QT5-控件-QLabel和QLCDNumber-标签显示图片或者视频,LCD用于上位机不错
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QLabel> #incl ...
- yum 安装 kvm
KVM是什么? for Kernel-based Virtual Machine 安装环境Centos 6.5 mini x64 禁用selinux, 禁用防火墙 安装过程: 1. 查看我们的电脑是 ...