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 ...
随机推荐
- VC2010对Excel的操作
1. 创建新的C++工程 创建基于对话框的MFC程序 2. 添加库.添加Excel类库 在工程名上右键,选择“添加”—“类”(或者点击菜单栏的“项目”->“添加类”),选择“TypeLib中的M ...
- 配置NFS服务器
一.配置NFS服务器 1.安装软件包 [root@wjb10000 ~]# yum -y install nfs-utils.x86_64 2.修改配置文件[root@wjb10000 ~]# vim ...
- SpringMVC08转发和重定向
public class User { private String name; private Integer age; public String getName() { return name; ...
- 新浪微博开放平台OAuth授权解决方案(含代码)
前几日一位朋友项目中需要使用新浪微博的接口,故和这位朋友一同研究了新浪微博开放平台上面所提供的资料,首先要使用这些接口是需要用户登录并且授权的,新浪微博开放平台其实是提供两种授权方式的,第一种是:OA ...
- nyoj 2
#include <iostream> #include <stack> #include <string.h> #include <stdio.h> ...
- 自己动手写easyui的checkbox
最近项目中用到了easyui这个框架,找了一圈也没有找到checkbox list控件,被迫只能自己实现了,为了便于复用,自己封装了下,有需要的,直接拿去用吧.有意见或建议的,欢迎指教啊. 调用示例 ...
- component object model(组件对象模型)
通常,COM是以 win32动态链接库(dll)或可执行文件(exe)的形式发布. 在COM中,接口就是一切,对于客户来说,一个组件就是一个接口集.COM接口是一个包含一个函数指针数组的内存结构. 组 ...
- 常用hash函数
常用的哈希函数 通用的哈希函数库有下面这些混合了加法和一位操作的字符串哈希算法.下面的这些算法在用法和功能方面各有不同,但是都可以作为学习哈希算法的实现的例子. 1.RS 从Robert S ...
- deep learning in nlp 资料文献
Deep Learning for Natural Language Processing (without Magic) http://nlp.stanford.edu/courses/NAACL2 ...
- 编程语言大牛王垠:编程的智慧,带你少走弯路 [本文转载CocoaChina]
作者:王垠 授权本站转载. 编程是一件创造性的工作,是一门艺术.精通任何一门艺术,都需要很多的练习和领悟,所以这里提出的“智慧”,并不是号称三天瘦二十斤的减肥药,它并不能代替你自己的勤奋.然而我希望它 ...