A
题意:n是否能被k个不同的正奇数表示。
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<set> #include<map> #include<stack> #include<queue> #include<vector> #include<sstream> typedef long long LL; const int INF = 0x3f3f3f3f; using namespace std; const int MAXN = 50000 + 10; const double eps = 1e-8; int dcmp(double a, double b){ if(fabs(a - b) < eps) return 0; return a < b ? -1 : 1; } int main(){ int T; scanf("%d", &T); while(T--){ LL n, k; scanf("%lld%lld", &n, &k); if(n >= k * k && (n + k) % 2 == 0) printf("YES "); else printf("NO "); } return 0; }
B
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<set> #include<map> #include<stack> #include<queue> #include<vector> #include<sstream> typedef long long LL; const int INF = 0x3f3f3f3f; using namespace std; const int MAXN = 100000 + 10; const double eps = 1e-8; int dcmp(double a, double b){ if(fabs(a - b) < eps) return 0; return a < b ? -1 : 1; } int g[MAXN], b[MAXN]; int main(){ int T; scanf("%d", &T); while(T--){ int n; scanf("%d", &n); for(int i = 1; i <= n; ++i){ g[i] = b[i] = 0; } for(int i = 1; i <= n; ++i){ int k, x; scanf("%d", &k); while(k--){ scanf("%d", &x); if(!g[i] && !b[x]){ g[i] = x; b[x] = i; } } } int ans1 = 0; int ans2 = 0; for(int i = 1; i <= n; ++i){ if(!g[i]){ ans1 = i; break; } } for(int i = 1; i <= n; ++i){ if(!b[i]){ ans2 = i; break; } } if(ans1){ printf("IMPROVE "); printf("%d %d ", ans1, ans2); } else{ printf("OPTIMAL "); } } return 0; }
C
题意:n*m的格子,有k个点,要求每个点都必须经过某个点。每次向某个方向移动,所有点是一起移动的,如果到了边界,则原地不动。问是否能在2mn步内使每个点都经过某个指定的点。
分析:将k个点都移到左上角,再遍历所有格子。
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<set> #include<map> #include<stack> #include<queue> #include<vector> #include<sstream> typedef long long LL; const int INF = 0x3f3f3f3f; using namespace std; const int MAXN = 50000 + 10; const double eps = 1e-8; int dcmp(double a, double b){ if(fabs(a - b) < eps) return 0; return a < b ? -1 : 1; } int main(){ int n, m, k; scanf("%d%d%d", &n, &m, &k); int x, y; for(int i = 0; i < 2 * k; ++i){ scanf("%d%d", &x, &y); } printf("%d ", (n - 1) + (m - 1) + (m - 1) * n + (n - 1)); for(int i = 0; i < n - 1; ++i) printf("U"); for(int i = 0; i < m - 1; ++i) printf("L"); for(int i = 0; i < n; ++i){ for(int j = 0; j < m - 1; ++j){ if(i % 2 == 0) printf("R"); else printf("L"); } if(i != n - 1) printf("D"); } printf(" "); return 0; }