A. Mystical Mosaic
题目大意:
给一个空白矩阵,每次可以选一些行和一些列并让他们的交点涂黑,每次选的行和列不能有交集。
给出最后的矩阵样子,问能不能经过若干次以上操作后得到最后的矩阵。
思路:
每一行都可以确定哪些列必须被覆盖记为Si,任意两个不同的行之间要么S相等要么相交为空集。
所以我们要做的就是确定任意两行,他们的S要么相等要么相交为空集,这是答案为Yes的充要条件。
代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 char table[55][55]; 5 6 int main() { 7 int n, m; 8 cin >> n >> m; 9 for (int i = 0; i < n; i++) cin >> table[i]; 10 bitset<55> col[55]; // 用bitset表示S 11 for (int i = 0; i < n; i++) { 12 for (int j = 0; j < m; j++) { 13 col[i][j] = table[i][j]==‘#‘?1:0; 14 } 15 } 16 bool flag = true; 17 for (int i = 0; i < n; i++) { 18 for (int j = i + 1; j < n; j++) { 19 for (int k = 0; k < m; k++) { 20 if (!(col[i]==col[j] || (col[i]&col[j]).count()==0)) 21 {flag=false; break;} 22 } 23 } 24 } 25 if (flag) cout << "Yes" << ‘\n‘; 26 else cout << "No" << ‘\n‘; 27 return 0; 28 }
B. Three-level Laser
题目大意:
给一个数组,从左到右依次选3个数a, b, c,让(a-b)/(a-c)最大。
思路:
代码:
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int a[maxn]; int n, u; int main() { while (cin >> n >> u) { for (int i = 0; i < n; i++) cin >> a[i]; int i = 0, k = i; double ans = -1; for (; i < n - 2; i++) { for (; k < n - 1 && a[k + 1] - a[i] <= u; k++) ; if (k - i >= 2) { ans = max(ans, 1 + 1.0 * (a[i] - a[i + 1]) / (a[k] - a[i])); } } printf("%.9lf\n", ans); } return 0; }
C. Riverside Curio
题目大意:
思路:
代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 100000 + 10; 4 typedef long long LL; 5 int a[maxn], t[maxn]; 6 int n; 7 int main() { 8 while (cin >> n) { 9 for (int i = 0; i < n; i++) cin >> a[i]; 10 int cur = 0; 11 for (int i = n - 1; i >= 0; i--) { 12 cur = t[i] = max(max(0, cur - 1), a[i] + 1); 13 } 14 LL ans = 0; cur = 0; 15 for (int i = 0; i < n; i++) { 16 ans += (cur = max(cur, t[i])); 17 } 18 for (int i = 0; i < n; i++) ans -= a[i] + 1; 19 cout << ans << ‘\n‘; 20 } 21 return 0; 22 }
D. Contact ATC
题目大意:
思路:
代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 typedef long long LL; 5 6 const int maxn = 100000 + 10; 7 // refer to model answer 8 struct fraction { 9 template <typename T> 10 static inline T gcd(const T a, const T b) { 11 return (b == 0) ? a : gcd(b, a % b); 12 } 13 14 LL num, deno; 15 16 inline void simplify() { 17 if (deno < 0) { num *= -1; deno *= -1; } 18 LL g = gcd(num < 0 ? -num : num, deno); 19 num /= g, deno /= g; 20 } 21 22 fraction() {} 23 fraction(LL num, LL deno):num(num), deno(deno) { simplify(); } 24 25 inline bool operator<(const fraction &rhs) const { 26 return num * rhs.deno < deno * rhs.num; 27 } 28 inline bool operator!=(const fraction &rhs) const { 29 return num * rhs.deno != deno * rhs.num; 30 } 31 }; 32 33 struct BIT { 34 static const int maxn = ::maxn; 35 int f[maxn]; 36 BIT() { memset(f, 0, sizeof f); } 37 inline void init() { memset(f, 0, sizeof f); } 38 inline void add(int pos, int inc) { 39 for (pos++; pos < maxn; pos += (pos & -pos)) 40 f[pos] += inc; 41 } 42 inline int sum(int rg) { 43 int ans = 0; 44 for (++rg; rg; rg -= (rg & -rg)) { 45 ans += f[rg]; 46 } 47 return ans; 48 } 49 inline int sum(int lf, int rg) { 50 return sum(rg) - sum(lf - 1); 51 } 52 }bit; 53 54 int n, w; 55 pair<fraction, fraction> t[maxn]; 56 pair<fraction, int> d[maxn]; 57 int p[maxn]; 58 59 int main() { 60 while (cin >> n >> w) { 61 for (int i = 0; i < n; i++) { 62 int x, v; cin >> x >> v; 63 // cout << x << ‘ ‘ << v << ‘\n‘; 64 t[i].first = fraction(-x, v - w); 65 t[i].second = fraction(-x, v + w); 66 } 67 // 排序。如果第一个时间相等则应该按照第二个时间从大到小排序 68 for (int i = 0; i < n; i++) t[i].second.num *= -1; 69 sort(t, t + n); 70 for (int i = 0; i < n; i++) t[i].second.num *= -1; 71 // for (int i = 0; i < n; i++) { 72 // printf("%lld %lld\n", t[i].first.num, t[i].first.deno); 73 // } 74 // 对速度为v+w的到达时间的离散化。第一个时间不用离散化,因为已经排序了,下标就是离散化 75 for (int i = 0; i < n; i++) { 76 d[i].first = t[i].second; 77 d[i].second = i; 78 } 79 sort(d, d + n); 80 for (int i = 0, rk = -1; i < n; i++) { 81 if (i == 0 || d[i].first != d[i - 1].first) rk++; 82 p[d[i].second] = rk; 83 } 84 // 求逆序对 85 LL ans = 0; bit.init(); 86 for (int i = 0; i < n; i++) { 87 ans += bit.sum(p[i], maxn - 2); 88 // cout << bit.sum(p[i], maxn - 1) << endl; 89 bit.add(p[i], 1); 90 } 91 cout << ans << ‘\n‘; 92 } 93 return 0; 94 }
原文地址:https://www.cnblogs.com/ZengWangli/p/8729317.html
时间: 2024-11-08 03:24:10