1. 程式人生 > >浪在ACM 集訓隊第九次測試賽 A+B

浪在ACM 集訓隊第九次測試賽 A+B

浪在ACM 集訓隊第九次測試賽

A. Paper Airplanes

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

  To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
  A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?

Input

  The only line contains four integers k, n, s, p (1≤k,n,s,p≤104) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.

Output

  Print a single integer — the minimum number of packs they should buy.

Examples

input
5 3 2 3
output
4
input
5 3 100 1
output
5

Note

  In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone’s needs.
  In the second sample they have to buy a pack for each person as they can’t share sheets.

解析

#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#ifndef NULL
#define NULL 0
#endif
using namespace std;

int main()
{
	long long k, n, s, p;
	cin >> k >> n >> s >> p;  //k個人,每人n個飛機,一張紙做s個飛機,一包裡有p張紙
	if (n%s == 0)   //先看n個飛機幾張紙
		n = n / s;
	else
		n = n / s + 1;
	k = k * n;   //總共用了幾張紙,紙不能公用,但每包的紙可以平分
	if (k%p == 0)   //要買幾包
		cout << k / p << endl;
	else
		cout << k / p + 1 << endl;
	return 0;
}

B. Battleship

time limit per test:1.5 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

Arkady is playing Battleship. The rules of this game aren’t really important.
There is a field of n×n cells. There should be exactly one k-decker on the field, i. e. a ship that is k cells long oriented either horizontally or vertically. However, Arkady doesn’t know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.
Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship.

Input

The first line contains two integers n and k (1≤k≤n≤100) — the size of the field and the size of the ship.
The next n lines contain the field. Each line contains n characters, each of which is either ‘#’ (denotes a definitely empty cell) or ‘.’ (denotes a cell that can belong to the ship).

Output

Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship.
If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.

Examples

input

4 3
#..#
#.#.
....
.###

output
3 2
input

10 4
#....##...
.#...#....
..#..#..#.
...#.#....
.#..##.#..
.....#...#
...#.##...
.#...#.#..
.....#..#.
...#.#...#
**output**
6 1
**input**
19 6
##..............###
#......#####.....##
.....#########.....
....###########....
...#############...
..###############..
.#################.
.#################.
.#################.
.#################.
#####....##....####
####............###
####............###
#####...####...####
.#####..####..#####
...###........###..
....###########....
.........##........
#.................#

output
1 8

Note

The picture below shows the three possible locations of the ship that contain the cell (3,2) in the first sample.
codeforce

解析

在一個圖裡放一個cell,這個cell可以橫著或者豎著放,求一個點,是cell經過次數最多的點.像上圖的(3,2)有三個cell經過了這個點,所以該點處的值為3.且為圖裡所有點最大的.
豎著找一遍,然後再橫著找一遍.
假設有x個空位,cell長度為k.那麼x中可以放cell的個數為(x-k)+1

#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#ifndef NULL
#define NULL 0
#endif
using namespace std;

char mp[110][110];
int n,m;
int strcp(int x, int y)
{
	int sum = 0, ans = 0;
	for (int i = max(x - m + 1, 0); i < min(x + m, n); i++) {
		if (mp[i][y] == '.')
			ans++;
		if (mp[i][y] == '#' || i == min(x + m, n) - 1) {
			if (ans >= m)
				sum += (ans - m) + 1;
			ans = 0;
		}
	}
	for (int i = max(y - m + 1, 0); i < min(y + m, n); i++) {
		if (mp[x][i] == '.')
			ans++;
		if (mp[x][i] == '#' || i == min(y + m, n) - 1) {
			if (ans >= m)
				sum += (ans - m) + 1;
			ans = 0;
		}
	}
	return sum;
}
int main()
{
	int ix=0,iy=0,maxx=0;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> mp[i];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) 
			if(mp[i][j]=='.'){
				int sum = strcp(i, j);
				if (sum > maxx) {
					maxx = sum;
					ix = i, iy = j;
				}
			}
	cout << ix+1 << ' ' << iy+1<<endl;
	return 0;
}