LA 7512 November 11th (思维漏洞)

题意:给定n*m个座椅,然后有b个是坏的,要做人,并且两个人不能相邻,问你最多坐多少人,最少坐多少人。

析:这个题其实并不难,只要当时一时没想清楚,结果就一直WA,就是最少的情况时,其实一个人可以占三个座位,而不是两个,就是这一点没想清楚,其他的就简单了。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e6 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};

int n, m, q;
vector<int> a[1010];

int main(){
    int T, ca = 0;
    scanf("%d", &T);
    while(T--){
        scanf("%d %d %d", &n, &m, &q);
        for(int i = 0; i <= n; ++i)  a[i].clear();
        int tmp1, tmp2;
        while(q--){
            scanf("%d %d", &tmp1, &tmp2);
            a[tmp1 + 1].push_back(tmp2 + 1);
        }
        for(int i = 1; i <= n; ++i)  sort(a[i].begin(), a[i].end());
        int ans1 = 0, ans2 = 0;
        for(int line = 1; line <= n; ++line){
            if(a[line].empty()){
                ans1 += (m+1) / 2;
                ans2 += (m+2) / 3;
                continue;
            }
            int head = 0, len = a[line].size();
            for(int i = 0; i < len; ++i){
                int lur = a[line][i];
                int cha = lur - head - 1;

                ans1 += (cha+1) / 2;
                ans2 += (cha+2) / 3;
                head = lur;
            }

            int lur = m + 1;
            int cha = lur - head - 1;
            ans1 += (cha+1) / 2;
            ans2 += (cha+2) / 3;
        }
        printf("Case #%d: %d %d\n", ++ca, ans1, ans2);
    }
    return 0;
}
时间: 2024-10-09 13:31:26

LA 7512 November 11th (思维漏洞)的相关文章

UVALive 7512 November 11th 题解

思路:心态大崩,最多不讲了,最少应该是三个一组,比如......应该是.S..S.,这样占的最多 代码: #include<set> #include<map> #include<cmath> #include<queue> #include<string> #include<cstdio> #include<cstring> #include<sstream> #include<algorithm>

November 11th 2016 Week 46th Friday

Keep in mind that neither success nor failure is ever final. 无论成败,皆非定局. The final is not coming, but we can predict it just based on the current situation. If we can't make some changes, the result may be already determined. Single is an opportunity

山东省历届省赛No.1 思维部分

Problem A:Rescue The Princess Description Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry  the princess set out immediately. Yet, the beast set a maze. Onl

任务调度框架-Quartz.Net

使用Quartz.Net依赖于以下3个组件:Common.Logging.dll.Common.Logging.Core.dll.Quartz.dll 简单封装 1 using Quartz; 2 using Quartz.Impl; 3 using System; 4 using System.Collections.Generic; 5 using System.Linq; 6 using System.Text; 7 using System.Threading.Tasks; 8 9 na

Quartz.NET 入门,带C#实例

概述 Quartz.NET是一个开源的作业调度框架,非常适合在平时的工作中,定时轮询数据库同步,定时邮件通知,定时处理数据等. Quartz.NET允许开发人员根据时间间隔(或天)来调度作业.它实现了作业和触发器的多对多关系,还能把多个作业与不同的触发器关联.整合了 Quartz.NET的应用程序可以重用来自不同事件的作业,还可以为一个事件组合多个作业. 参考 官方学习文档:http://www.quartz-scheduler.net/documentation/index.html 使用实例

转载:Quartz.NET 入门

分享自:http://www.cnblogs.com/jys509/p/4628926.html 概述 Quartz.NET是一个开源的作业调度框架,非常适合在平时的工作中,定时轮询数据库同步,定时邮件通知,定时处理数据等. Quartz.NET允许开发人员根据时间间隔(或天)来调度作业.它实现了作业和触发器的多对多关系,还能把多个作业与不同的触发器关联.整合了 Quartz.NET的应用程序可以重用来自不同事件的作业,还可以为一个事件组合多个作业. 参考 官方学习文档:http://www.q

Quartz Scheduler(2.2.1) - Usage of CronTriggers

Cron is a UNIX tool that has been around for a long time, so its scheduling capabilities are powerful and proven. The CronTrigger class is based on the scheduling capabilities of cron. CronTrigger uses “cron expressions”, which are able to create fir

我的2015技术学习流水账

我的2015技术学习流水账 2015年马上就要过去了,匆匆忙忙地又是一年.回头总结整理,发现这一年还挺充实的.在正常上班工作之余,学习到了不少新东西,不禁感到很欣慰!一个多月前就开始写,终于赶在2016年来临之前写完了这篇文章-- 关于本文,尽管叫做流水账,但是出于程序员条理性的"强迫症",还是进行系统分类,分类方法参照Thoughtworks技术雷达的Tecniques.Languages & Frameworks.Tools.Platforms,将其中的Tecniques改

ZOJ 3635 Cinema in Akiba[ 树状数组 ]

传送门:ZOJ 3635 Cinema in Akiba Time Limit: 3 Seconds      Memory Limit: 65536 KB Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is full of people. The layout of CIA is very interesting, as there is only on