传送门: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 (模拟搜索)的更多相关文章

  1. HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)

    HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...

  2. 【LOJ6254】最优卡组 堆(模拟搜索)

    [LOJ6254]最优卡组 题面 题解:常用的用堆模拟搜索套路(当然也可以二分).先将每个卡包里的卡从大到小排序,然后将所有卡包按(最大值-次大值)从小到大排序,并提前处理掉只有一张卡的卡包. 我们将 ...

  3. 【BZOJ4524】[Cqoi2016]伪光滑数 堆(模拟搜索)

    [BZOJ4524][Cqoi2016]伪光滑数 Description 若一个大于1的整数M的质因数分解有k项,其最大的质因子为Ak,并且满足Ak^K<=N,Ak<128,我们就称整数M ...

  4. 【BZOJ4345】[POI2016]Korale 堆(模拟搜索)

    [BZOJ4345][POI2016]Korale Description 有n个带标号的珠子,第i个珠子的价值为a[i].现在你可以选择若干个珠子组成项链(也可以一个都不选),项链的价值为所有珠子的 ...

  5. JavaScript在表格中模拟搜索多关键词搜索和筛选

    模拟搜索需要实现以下功能: 1.用户的模糊搜索不区分大小写,需要小写字母匹配同样可以匹配到该字母的大写单词. 2.多关键词模糊搜索,假设用户关键词以空格分隔,在关键词不完整的情况下仍然可以匹配到包含该 ...

  6. 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 ...

  7. 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 ...

  8. POJ 3829 Seat taking up is tough(——只是题目很长的模拟)

    题目链接: http://poj.org/problem?id=3829 题意描述: 输入矩阵的大小n和m,以及来占位置的人数k 输入n*m的教室座位矩阵,每个值表示该座位的满意度 输入每个人来占位置 ...

  9. hdu 2629 Identity Card (字符串解析模拟题)

    这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...

随机推荐

  1. soundPool和audiofocus

    audiofocus试验: 使用soundPool来写一个播放音频的porject. 资源初始化: setContentView(R.layout.activity_main); Button bt1 ...

  2. QP01 BAPI、QP02 BDC

    近期在改动一个检验计划分配的一个程序.上网查了一些资料,分别对QP01检验计划创建.改动QP02.删除物料等操作.分享一下. 一.QP01 BAPI BAPI_INSPECTIONPLAN_CREAT ...

  3. Qt Style Sheets帮助文档 Overview

    Qt Style Sheets are a powerful mechanism that allows you to customize the appearance of widgets, in ...

  4. yii console.php 报错 Property "CConsoleApplication.theme" is not defined.

    默认配置的话,是不会出现这个错误的,应该是有人为修改了 yiic.php 这个文件,本来是 $config 载入的应该是 console.php ,人为修改后载入了 main.php 这个配置文件了 ...

  5. 触摸事件 Touch MotionEvent ACTION

    MotionEvent简介 当用户触摸屏幕时,将创建一个MontionEvent对象,MotionEvent包含了关于发生触摸的位置.时间信息,以及触摸事件的其他细节. 获取MontionEvent对 ...

  6. ajax与Servlet

    1.后台返回text类型的数据 <%@ page language="java" import="java.util.*" pageEncoding=&q ...

  7. noip 2012 开车旅行

    /*考场上写的暴力 40分钟70分*/ #include<iostream> #include<cstdio> #include<cstring> #define ...

  8. sharepoint查询超出阈值

    昨天客户出了webpart显示数据不稳定的bug,经过这两天的艰苦排查终于发现了是列表视图阈值造成的问题,经过在网上搜索终于找到了类似的解决方法. SPQuery query = new SPQuer ...

  9. (转)asp.net 使用cookie完成记住密码自动登录

     代码如下 复制代码 string username = this.txtUserName.Text;//用户名        string password = this.txtPassword.T ...

  10. java中的final, finally, finalize的区别

    final修饰符(关键字),如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承.因此一个类不能既被声明为abstract的,又被声明为final的.将变量或方法声明为fin ...