本文共 1786 字,大约阅读时间需要 5 分钟。
水
/* 水题*/#include #include #include #include #include #include #include #include using namespace std;int main(void){ //freopen ("A.in", "r", stdin); map m1; map m2; int n; while (~scanf ("%d", &n)) { for (int i=1; i<=26; ++i) { m1[i] = 0; m2[i] = 0; } char s[110]; scanf ("%s", &s); for (int i=0; i<=n-1; ++i) { if (s[i]<='z' && s[i]>='a') { int x = s[i] - 'a' + 1; m1[x]++; } else { int y = s[i] - 'A' + 1; m2[y]++; } } bool flag = true; for (int i=1; i<=26; ++i) { if (m1[i] == 0 && m2[i] == 0) { flag = false; break; } } (flag) ? puts ("YES") : puts ("NO"); } return 0;}
BFS
题意:给出n,m两个数字,n可以*2,或者-1,问最少几步n变成m
#include #include #include #include #include #include #include #include #include using namespace std;const int MAXN = 2e4 + 10;const int INF = 0x3f3f3f3f;int dp[MAXN];int used[MAXN];struct NODE{ int x; int cnt;}s;void BFS(int n, int m){ if (n >= m) { printf ("%d\n", n - m); return ; } queue q; s.x = n; s.cnt = 0; used[n] = 1; q.push (s); NODE a, b; while (!q.empty()) { a = q.front(); b = q.front(); q.pop(); a.x *= 2; a.cnt++; b.x -= 1; b.cnt++; if (a.x == m) { printf ("%d\n", a.cnt); break; } if (b.x == m) { printf ("%d\n", b.cnt); } if (a.x > 0 && a.x < MAXN && !used[a.x]) { q.push (a); used[a.x] = 1; } if (b.x > 0 && b.x < MAXN && !used[b.x]) { q.push (b); used[b.x] = 1; } } }int main(void){ //freopen ("B.in", "r", stdin); int n, m; int ans; while (~scanf ("%d%d", &n, &m)) { memset (used, 0, sizeof (used)); BFS (n, m); } return 0;}
转载于:https://www.cnblogs.com/Running-Time/p/4366791.html