被进爷坑了,第二天的比赛改到了12点
/************************************************ * Author :Running_Time * Created Time :2015/10/3 星期六 21:53:09 * File Name :A.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 55; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double EPS = 1e-8; bool r[N], c[N]; int main(void) { memset (r, false, sizeof (r)); memset (c, false, sizeof (c)); int n; scanf ("%d", &n); vector<int> ans; n = n * n; for (int x, y, i=1; i<=n; ++i) { scanf ("%d%d", &x, &y); if (!r[x] && !c[y]) { r[x] = c[y] = true; ans.push_back (i); } } for (int i=0; i<ans.size (); ++i) { printf ("%d%c", ans[i], (i == ans.size () - 1) ? ' ' : ' '); } return 0; }
/************************************************ * Author :Running_Time * Created Time :2015/10/3 星期六 21:53:24 * File Name :B.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 1e3 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double EPS = 1e-8; int a[N]; int main(void) { int n; scanf ("%d", &n); for (int i=1; i<=n; ++i) { scanf ("%d", &a[i]); } int ans = 0, d = 1, m = 0, p = 0; bool flag = false; while (true) { if (d == 1) { for (int i=p+1; i<=n; ++i) { if (m >= a[i]) { a[i] = INF; m++; p = i; flag = true; } } if (m == n) break; d ^= 1; ans++; } else { for (int i=p-1; i>=1; --i) { if (m >= a[i]) { a[i] = INF; m++; p = i; flag = true; } } if (m == n) break; d ^= 1; ans++; } } printf ("%d ", ans); return 0; }
题意:给了一张GCD表,问原来的求GCD的那些数
分析:从大到小找,最大的数和其他的数的GCD都不大于它,每次找到一个就能把它和已知的答案的GCD给删除,map+暴力就可以了
/************************************************ * Author :Running_Time * Created Time :2015/10/3 星期六 21:53:35 * File Name :C.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 5e2 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double EPS = 1e-8; int a[N*N]; int ans[N]; map<int, int> cnt; int GCD(int a, int b) { return b ? GCD (b, a % b) : a; } int main(void) { int n; scanf ("%d", &n); int m = n; n = n * n; for (int i=1; i<=n; ++i) { scanf ("%d", &a[i]); cnt[-a[i]]++; } int pos = m; map<int, int>::iterator it; for (it=cnt.begin (); it!=cnt.end (); ++it) { int x = -it -> first; while (it -> second) { ans[pos] = x; --it -> second; for (int i=pos+1; i<=m; ++i) { cnt[-GCD (ans[pos], ans[i])] -= 2; } pos--; } } for (int i=1; i<=m; ++i) { printf ("%d%c", ans[i], (i == m) ? ' ' : ' '); } return 0; }