BZOJ1407: [Noi2002]Savage
2018-01-16 10:38
399 查看
1407: [Noi2002]Savage
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 2357 Solved: 1056
[Submit][Status][Discuss]
Description
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <queue> #include <vector> #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define abs(a) ((a) < 0 ? (-1 * (a)) : (a)) inline void swap(int &a, int &b) { int tmp = a;a = b;b = tmp; } inline void read(int &x) { x = 0;char ch = getchar(), c = ch; while(ch < '0' || ch > '9') c = ch, ch = getchar(); while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar(); if(c == '-') x = -x; } const int INF = 0x3f3f3f3f; const int MAXN = 15; int c[MAXN + 5], p[MAXN + 5], l[MAXN + 5], n, ma; void exgcd(int a, int b, int &x, int &y) { if(!b){x = 1;y = 0;return;} exgcd(b, a % b, y, x); y -= a / b * x; return; } int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } bool judge(int m) { for(register int i = 1;i <= n;++ i) for(register int j = i + 1;j <= n;++j) { //先求方程 (pj - pi)x + my = ci - cj的最小正整数解x int P = p[j] - p[i], C = c[i] - c[j], g = gcd(P, m), M = m, x = 0, y = 0; if(C % g != 0) continue; P /= g, C /= g, M /= g; exgcd(P, M, x, y); M = M < 0 ? -M : M; x = (x * C % M + M) % M; if(!x) x += M; if(x <= min(l[i], l[j])) return 0; } return 1; } int main() { read(n); for(register int i = 1;i <= n;++ i) read(c[i]), read(p[i]), read(l[i]), ma = max(ma, c[i]); for(register int i = ma;;++ i) if(judge(i)){printf("%d", i);return 0;} }
BZOJ1047
相关文章推荐
- bzoj 1407: [Noi2002]Savage【扩展欧几里得+中国剩余定理】
- 【扩展欧几里得】Bzoj 1407: [Noi2002]Savage
- BZOJ1407: [Noi2002]Savage
- BZOJ1407 [Noi2002]Savage 【扩展欧几里得】
- BZOJ1407_NOI2002_荒岛野人_Savage_C++
- 【BZOJ 1407】 [Noi2002]Savage
- bzoj 1407: [Noi2002]Savage
- 【bzoj 1407】【Noi2002】Savage
- 【NOI2002】【bzoj1407】Savage
- BZOJ 1407: [Noi2002]Savage( 数论 )
- bzoj1407[Noi2002] Savage
- [BZOJ 1407][NOI 2002]Savage(中国剩余定理+扩展欧几里得)
- 【BZOJ】1407 NOI 2002 荒岛野人Savage
- bzoj1407: [Noi2002]Savage
- 【BZOJ1407】 [Noi2002]Savage
- 【扩展欧几里得】Bzoj 1407: [Noi2002]Savage
- [BZOJ1407][Noi2002]Savage
- [BZOJ1407][NOI2002]Savage(扩展欧几里德)
- 【bzoj1407】 Noi2002—Savage
- BZOJ1407: [Noi2002]Savage