1255. Graveyard of the Cosa Nostra
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
There is a custom among the Ural Mafiosi — a big Mafioso’s coffin is to be carried by all his subordinates. The length of the coffin (in meters) equals to the number of the Mafioso’s subordinates in order not to let the carriers to encumber each other. As it happens, according to the ancient custom the width of a coffin is equal to 1 meter. So, the length of a coffin shows a dead man’s authority. By the way, the Ural Mafiosi are very scrupulous in matters of authority and will not bear neighborhood with less authoritative Mafioso. So, at one cemetery it’s possible to bury Mafiosi with equal authority. According to the Mafiosi’s custom a cemetery must be square. A cemetery length must be an integer number of meters.
You are to count how many Mafiosi can be buried on the cemetery of the given size. Coffins must be parallel to cemetery borders, coffins mustn’t overlap each other and get off the cemetery.
Input
Contains two numbers — a length of the cemetery N (1 < N < 10000) and a length of a coffin K (1 < K< 10000).
Output
The single integer number — the most amount of the coffins of the size 1×K that may be buried at the cemetery of the size N×N.
Sample
input | output |
---|---|
5 4 |
6 |
Problem Author: Stanislav Vasilyev, Alexey Lakhtin
Problem Source: Open collegiate programming contest for student teams, Ural State University, March 15, 2003
Problem Source: Open collegiate programming contest for student teams, Ural State University, March 15, 2003
Tags: none (hide tags for unsolved problems)
Difficulty: 267
题意:给出n,k问一个n*n的正方形,最多可以塞下多少1*k的小矩阵。
分析:比较经典的问题。
献给正方形染色,
1 2 3 ...... k 1 2 ....... k 1 ..... n%k
2 3 4 ....k 1 2 3 .....k 1 2 ....
这样染色。
可以保证每放下一个矩阵,都会覆盖到1..k的颜色各一次。
显然答案是颜色的最小个数。
也就是,问题转变成了求染色后的正方形颜色个数最小是多少。
证明我也不会,但看上去就是对的。。。。。
所以按照这个思路就可以求了。
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} int n, k; inline void Input()
{
cin >> n >> k;
} inline void Solve()
{
if(n < k) cout << << endl;
else cout << ((n / k) * n) + ((n % k) * (n / k)) + max( * (n % k) - k, ) << endl;
} int main()
{
freopen("a.in", "r", stdin);
Input();
Solve();
return ;
}