## [1004 Wave](http://acm.hdu.edu.cn/showproblem.php?pid=6570)
思路
存下每种数字的位置,
AC代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #include<iostream> #include<cmath> #include<stdio.h> #include<bits/stdc++.h> #define LL long long #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fix fixed << setprecision(3) using namespace std; int mod = 1e9 + 7; const int INF = 1e9 + 7; const double PI = 45.0 / atan(1.0); vector<int> vec[105]; int main() { fio; int n, c, x; cin >> n >> c; for(int i = 1; i <= n; ++i) { cin >> x; vec[x].push_back(i); } int ans = 0; for(int i = 1; i <= c; ++i) { for(int j = 1; j <= c; ++j) { if(i == j) continue; int len1 = vec[i].size(); int len2 = vec[j].size(); int st1 = 0, st2 = 0, temp = 0, sum = 0; while(1) { while(st1 < len1 && vec[i][st1] < temp) { st1 += 1; } if(st1 == len1) break; temp = vec[i][st1]; sum += 1; while(st2 < len2 && vec[j][st2] < temp) { st2 += 1; } if(st2 == len2) break; sum += 1; temp = vec[j][st2]; } ans = max(ans, sum); } } cout << ans << endl; return 0; }
|
思路
- 这是什么神仙思路,假设区间趋于0,则可以看成是两个点,计算不相交的情况,就是第一个区间n种,第二个区间(n - 1)种,左右算两遍就是
- 具体
AC代码
思路
最小公倍数
AC代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#pragma comment(linker, "/STACK:102400000,102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <sstream> #include <vector> #include <cstdio> #include <bitset> #include <string> #include <cmath> #include <deque> #include <queue> #include <stack> #include <map> #include <set> using namespace std; typedef long long ll; const double pi = acos(-1.0); const int eps = 1e-10; const int mod = 1e9 + 7; #define debug(a) cout << "*" << a << "*" << endl const int INF = 0x3f3f3f3f; const int maxn = 100005;
ll read() { ll x = 0,f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; }
ll LCM(ll a, ll b) { return a * b / __gcd(a, b); } ll t, n, m, a[maxn], b[maxn]; int main() {
while (~scanf("%lld%lld", &n, &m)) { ll temp = 1; ll sum = 0, sum1 = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); temp = LCM(a[i], temp); sum1 += a[i]; } for (int i = 1; i <= n; i++) { b[i] = temp / a[i]; sum += b[i]; } if (!(m % sum)) { printf("Yes\n"); for (int i = 1; i <= n; i++) { printf(i == n ? "%lld\n" : "%lld ", b[i] * (m / sum)); } } else { printf("No\n"); } } return 0; }
|
思路
遍历使得任意a[i]!=b[j]+xa[i]!=b[j]+x,求最小的x;
AC代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#pragma comment(linker, "/STACK:102400000,102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <sstream> #include <vector> #include <cstdio> #include <bitset> #include <string> #include <cmath> #include <deque> #include <queue> #include <stack> #include <map> #include <set> using namespace std; typedef long long ll; const double pi = acos(-1.0); const int eps = 1e-10; const int mod = 1e9 + 7; #define debug(a) cout << "*" << a << "*" << endl const int INF = 0x3f3f3f3f;
const int maxn = 1e6 + 5;
ll read() { ll x = 0,f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int t, n, m, a[maxn], b[maxn], v[maxn]; int main() { while (~scanf("%d%d", &n, &m)) { memset(v, 0, sizeof(v)); for (int i = 0; i < n; i++) a[i] = read(); for (int i = 0; i < m; i++) b[i] = read(); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i] >= b[j]) { v[a[i] - b[j]] = 1; } } } for (int i = 0;; i++) if (!v[i]) { printf("%d\n", i); break; }
} return 0; }
|