ural 1157. Young Tiler
1157. Young Tiler
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
One young boy had many-many identical square tiles. He loved putting all his tiles to form a rectangle more, than anything in the world — he has learned the number of all rectangles he can form using his tiles. On his birthday he was presented a number of new tiles. Naturally, he started forming rectangles from these tiles — the thing he loved most of all! Soon he has learned all rectangles he could form with a new number of tiles.
Here we should notice that boy can easily count the number of rectangles, but he has difficulty counting the number of tiles — there are too much of them for such a young boy. But it will not be difficult for you to determine how many tiles he has now, knowing how many rectangles he could form before, how many rectangles he can form now, and how many tiles he got as a birthday present.
You are given numbers M, N and K. You should find the smallest number L, such as you can form Ndifferent rectangles using all L tiles, and form M rectangles using L − K tiles.
Input
One line containing three integers: M, N, K (1 ≤ M, N, K ≤ 10000).
Output
If L is less than or equal to 10000, then print that number (if there is a number of such L, you should print the smallest one). If there is no solution or smallest L is greater than 10000, print 0.
Sample
input | output |
---|---|
2 3 1 |
16 |
Problem Source: Ural Collegiate Programming Contest, April 2001, Perm, English Round
Tags: none
Difficulty: 164
题意:给出M,N,K,要求出最少的小正方形L,使L个小正方形可以拼出N种矩形,L-K个小正方形可以拼出M种矩形
分析:所谓拼图形,就是求(因数个数+1)/2罢了,也就是1~sqrt(l)的因数个数。。。
因为题目限制l<=10000
所以暴力即可
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <deque> 6 #include <vector> 7 #include <queue> 8 #include <iostream> 9 #include <algorithm> 10 #include <map> 11 #include <set> 12 #include <ctime> 13 using namespace std; 14 typedef long long LL; 15 typedef double DB; 16 #define For(i, s, t) for(int i = (s); i <= (t); i++) 17 #define Ford(i, s, t) for(int i = (s); i >= (t); i--) 18 #define Rep(i, t) for(int i = (0); i < (t); i++) 19 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--) 20 #define rep(i, x, t) for(int i = (x); i < (t); i++) 21 #define MIT (2147483647) 22 #define INF (1000000001) 23 #define MLL (1000000000000000001LL) 24 #define sz(x) ((int) (x).size()) 25 #define clr(x, y) memset(x, y, sizeof(x)) 26 #define puf push_front 27 #define pub push_back 28 #define pof pop_front 29 #define pob pop_back 30 #define ft first 31 #define sd second 32 #define mk make_pair 33 inline void SetIO(string Name) { 34 string Input = Name+".in", 35 Output = Name+".out"; 36 freopen(Input.c_str(), "r", stdin), 37 freopen(Output.c_str(), "w", stdout); 38 } 39 40 inline int Getint() { 41 int Ret = 0; 42 char Ch = ' '; 43 while(!(Ch >= '0' && Ch <= '9')) Ch = getchar(); 44 while(Ch >= '0' && Ch <= '9') { 45 Ret = Ret*10+Ch-'0'; 46 Ch = getchar(); 47 } 48 return Ret; 49 } 50 51 const int N = 10010; 52 int n, m, k; 53 int Dp[N]; 54 bool Visit[N]; 55 56 inline void Input() { 57 scanf("%d%d%d", &n, &m, &k); 58 } 59 60 inline int Search(int x) { 61 if(Visit[x]) return Dp[x]; 62 Visit[x] = 1; 63 int t = sqrt(x)+1e-6; 64 For(i, 1, t) 65 if(!(x%i)) Dp[x]++; 66 return Dp[x]; 67 } 68 69 inline void Solve() { 70 For(i, k+1, 10000) 71 if(Search(i) == m && Search(i-k) == n) { 72 printf("%d\n", i); 73 return; 74 } 75 puts("0"); 76 } 77 78 int main() { 79 #ifndef ONLINE_JUDGE 80 SetIO("H"); 81 #endif 82 Input(); 83 Solve(); 84 return 0; 85 }