1121 Damn Single
模拟
1 // 1121 Damn Single 2 #include <map> 3 #include <vector> 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 using namespace std; 8 9 map<int, int> m, vis; 10 vector<int> p; 11 const int N = 1e4 + 10; 12 int a[N]; 13 14 int main() { 15 int n, x, y; 16 scanf("%d", &n); 17 while (n--) { 18 scanf("%d %d", &x, &y); 19 x++; y++; 20 m[x] = y; 21 m[y] = x; 22 } 23 scanf("%d", &n); 24 for (int i = 1; i <= n; i++) { 25 scanf("%d", &a[i]); 26 a[i]++; 27 vis[a[i]] = 1; 28 } 29 for (int i = 1; i <= n; i++) { 30 if (vis[ m[a[i]] ]) continue; 31 p.push_back(a[i]); 32 } 33 sort(p.begin(), p.end()); 34 printf("%d\n", p.size()); 35 for (int i = 0; i < p.size(); i++) { 36 if (i != 0) printf(" "); 37 printf("%05d", p[i] - 1); 38 } 39 return 0; 40 }
1122 Hamiltonian Cycle
模拟
1 // 1122 Hamiltonian Cycle 2 #include <set> 3 #include <cstdio> 4 #include <cstring> 5 #include <iostream> 6 #include <algorithm> 7 using namespace std; 8 9 const int N = 205; 10 int MAP[N][N]; 11 set<int> s; 12 13 int main() { 14 memset(MAP, -1, sizeof(MAP)); 15 int n, m, k; 16 scanf("%d %d", &n, &m); 17 for (int i = 1; i <= m; i++) { 18 int u, v; 19 scanf("%d %d", &u, &v); 20 MAP[u][v] = 1; MAP[v][u] = 1; 21 } 22 scanf("%d", &k); 23 while (k--) { 24 bool f = 1; 25 int u, v, root; 26 scanf("%d", &m); 27 scanf("%d", &root); 28 s.insert(root); 29 u = root; 30 for (int i = 1; i < m; i++) { 31 scanf("%d", &v); 32 s.insert(v); 33 if (MAP[u][v] == -1) f = 0; 34 u = v; 35 } 36 if (root != u || s.size() != n || m != n + 1) f = 0; 37 if (!f) printf("NO\n"); 38 else printf("YES\n"); 39 s.clear(); 40 } 41 return 0; 42 }
1124 Raffle for Weibo Followers
MAP标记
1 // 1124 Raffle for Weibo Followers 2 #include <map> 3 #include <cstdio> 4 #include <vector> 5 #include <iostream> 6 #include <algorithm> 7 using namespace std; 8 9 map<string, int> vis; 10 string str; 11 12 int main() { 13 bool f = 0; 14 int n, m, s, cnt; 15 cin >> n >> m >> s; 16 cnt = m; 17 for (int i = 1; i < s; i++) cin >> str; 18 for (int i = s; i <= n; i++) { 19 cin >> str; 20 if (cnt == m && !vis[str]) { 21 f = 1; 22 cout << str << endl; 23 cnt = 1; 24 vis[str] = 1; 25 } 26 if (!vis[str]) cnt++; 27 } 28 if (!f) cout << "Keep going..." << endl; 29 return 0; 30 }
1125 Chain the Ropes
思维
1 // 1125 Chain the Ropes 2 #include <cstdio> 3 #include <iostream> 4 #include <algorithm> 5 using namespace std; 6 7 const int N = 1e4 + 10; 8 int a[N]; 9 10 int main() { 11 int n, ans = 0; 12 cin >> n; 13 for (int i = 1; i <= n; i++) cin >> a[i]; 14 sort(a + 1, a + 1 + n); 15 ans = a[1]; 16 for (int i = 2; i <= n; i++) { 17 ans += a[i]; 18 ans /= 2; 19 } 20 cout << ans << endl; 21 return 0; 22 }
原文地址:https://www.cnblogs.com/ehanla/p/10860178.html
时间: 2024-10-08 08:00:04