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.
解析
在一个图里放一个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;
}