ural 1255. Graveyard of the Cosa Nostra
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
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的颜色各一次。
显然答案是颜色的最小个数。
也就是,问题转变成了求染色后的正方形颜色个数最小是多少。
证明我也不会,但看上去就是对的。。。。。
所以按照这个思路就可以求了。
1 /** 2 Create By yzx - stupidboy 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <cmath> 8 #include <deque> 9 #include <vector> 10 #include <queue> 11 #include <iostream> 12 #include <algorithm> 13 #include <map> 14 #include <set> 15 #include <ctime> 16 #include <iomanip> 17 using namespace std; 18 typedef long long LL; 19 typedef double DB; 20 #define MIT (2147483647) 21 #define INF (1000000001) 22 #define MLL (1000000000000000001LL) 23 #define sz(x) ((int) (x).size()) 24 #define clr(x, y) memset(x, y, sizeof(x)) 25 #define puf push_front 26 #define pub push_back 27 #define pof pop_front 28 #define pob pop_back 29 #define ft first 30 #define sd second 31 #define mk make_pair 32 33 inline int Getint() 34 { 35 int Ret = 0; 36 char Ch = ' '; 37 bool Flag = 0; 38 while(!(Ch >= '0' && Ch <= '9')) 39 { 40 if(Ch == '-') Flag ^= 1; 41 Ch = getchar(); 42 } 43 while(Ch >= '0' && Ch <= '9') 44 { 45 Ret = Ret * 10 + Ch - '0'; 46 Ch = getchar(); 47 } 48 return Flag ? -Ret : Ret; 49 } 50 51 int n, k; 52 53 inline void Input() 54 { 55 cin >> n >> k; 56 } 57 58 inline void Solve() 59 { 60 if(n < k) cout << 0 << endl; 61 else cout << ((n / k) * n) + ((n % k) * (n / k)) + max(2 * (n % k) - k, 0) << endl; 62 } 63 64 int main() 65 { 66 freopen("a.in", "r", stdin); 67 Input(); 68 Solve(); 69 return 0; 70 }