Codeforces 919C - Seat Arrangements
传送门:http://codeforces.com/contest/919/problem/C
给出一张n×m的座位表(有已占座位和空座位),请选择同一行(或列)内连续的k个座位。求选择的方法数。
Hack:首先,若k=1,则所有的空座位均可选,方法数即为空座位数。
对于某一行(或列)中连续的len个座位,选择的方法数为len-k+1。
于是,分别逐行、逐列地统计,求出答案。参考程序如下:
#include <stdio.h>
#define MAX_N 2000 char map[MAX_N][MAX_N];
int row[MAX_N][MAX_N], col[MAX_N][MAX_N]; int main(void)
{
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = ; i < n; i++) {
getchar();
for (int j = ; j < m; j++)
map[i][j] = getchar();
}
int ans = ;
if (k == ) {
for (int i = ; i < n; i++) {
for (int j = ; j < m; j++)
if (map[i][j] == '.') ans++;
}
printf("%d\n", ans);
return ;
}
//pass by row
for (int i = ; i < n; i++) {
int len = , cnt = ;
for (int j = ; j < m; j++) {
if (map[i][j] == '*') {
if (len) row[i][cnt++] = len;
len = ;
}
else len++;
}
if (len) row[i][cnt++] = len;
}
//pass by column
for (int j = ; j < m; j++) {
int len = , cnt = ;
for (int i = ; i < n; i++) {
if (map[i][j] == '*') {
if (len) col[j][cnt++] = len;
len = ;
}
else len++;
}
if (len) col[j][cnt++] = len;
}
for (int i = ; i < n; i++) {
for (int j = ; row[i][j] != ; j++)
if (row[i][j] >= k) ans += row[i][j] - k + ;
}
for (int i = ; i < m; i++) {
for (int j = ; col[i][j] != ; j++)
if (col[i][j] >= k) ans += col[i][j] - k + ;
}
printf("%d\n", ans);
return ;
}
Codeforces 919C - Seat Arrangements的更多相关文章
- codeforces 919C Seat Arrangements 思维模拟
C. Seat Arrangements time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #460 (Div. 2)-C. Seat Arrangements
C. Seat Arrangements time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- Codeforces 919 C. Seat Arrangements
C. Seat Arrangements time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 【Codeforces Round #460 (Div. 2) C】 Seat Arrangements
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用pre[i][j]表示第i行前j列的和. 然后枚举连续座位的最左上点. (有两种可能向右或向下k个. 则还需要处理出pre2[i] ...
- Codeforces.838D.Airplane Arrangements(思路)
题目链接 \(Description\) 飞机上有n个位置.有m个乘客入座,每个人会从前门(1)或后门(n)先走到其票上写的位置.若该位置没人,则在这坐下:若该位置有人,则按原方向向前走直到找到空座坐 ...
- Codeforces Round #460 (Div. 2)
A. Supermarket We often go to supermarkets to buy some fruits or vegetables, and on the tag there pr ...
- Codeforces Gym 100463E Spies 并查集
Spies Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Desc ...
- Codeforces 725B Food on the Plane
B. Food on the Plane time limit per test:2 seconds memory limit per test:256 megabytes input:standar ...
- Codeforces 839B Game of the Rows【贪心】
B. Game of the Rows time limit per test:1 second memory limit per test:256 megabytes input:standard ...
随机推荐
- codevs1574广义斐波那契数列
1574 广义斐波那契数列 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 广义的斐波那契数列是指形如an=p* ...
- [Swift通天遁地]四、网络和线程-(5)解析网络请求数据:String(字符串)、Data(二进制数据)和JSON数据
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- wcf 代理配置
<?xml version="1.0" encoding="utf-8"?> <configuration> <appSett ...
- Java中static方法
今天学习到了并且应用到了java中的静态方法,并且了解到它的好处与缺点. ● 生命周期(Lifecycle): 静态方法(Static Method)与静态成员变量一样,属于类本身,在类装载的时候被装 ...
- android webview 简单应用
一直没有用过webView 在网上找了一个小例子,主要实现以下功能: 1.当webview加载网页的时候在标题栏上显示加载进度 2.隐藏webkit浏览器的地址栏 3.设置程序的标题为网页的标题 4. ...
- excel另存为csv
# -*- coding: utf-8 -*- """ Created on Tue Jul 11 21:25:57 2017 import pandas as pd i ...
- UNIX环境高级编程--2
UNIX标准及实现 ISO C: 国际标准化组织(International Organization for standardization , ISO)ISO C标准的意图是提供C程序的可移植性, ...
- [转]linux之patch命令
转自:http://blog.chinaunix.net/uid-9525959-id-2001542.html patch [选项] [原始文件 [补丁文件]] [功能] 给文件1应用补丁文件变成另 ...
- scala控制流程语句
直接上代码了哈. package com.test.scala.test object Kongzi { def main(args: Array[String]): Unit = { //if 语句 ...
- Struts2 之 实现文件上传(多文件)和下载
Struts2 之 实现文件上传和下载 必须要引入的jar commons-fileupload-1.3.1.jar commons-io-2.2.jar 01.文件上传需要分别在struts.xm ...