## Codeforces Round #295 (Div. 2) ABC

2019年02月20日 ⁄ 综合 ⁄ 共 2447字 ⁄ 字号 评论关闭

A - Pangram :判断一个字符串中有木有出现过26个字母，不论大小写，有YES没有NO

```#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
const int inf = 0x3f3f3f3f;

char a[1000];
int cnt;
int vis[30];

int main()
{
int n;
while( ~scanf("%d", &n ))
{
scanf("%s", a);
if( n < 26 )
{
cout << "NO" << endl;
continue;
}
cnt = 0;
int len = strlen( a );
memset( vis, 0, sizeof( vis ));
for( int i = 0; i < len; i++ )
{
if( a[i] <= 'z' && a[i] >= 'a' )
{
if( !vis[ a[i] - 'a' ] )
{
cnt++;
vis[ a[i] -'a' ] = 1;
}
}
else
{
if( !vis[ a[i] - 'A'] )
{
cnt++;
vis[ a[i] - 'A' ] = 1;
}
}
}
if( cnt == 26 )
puts("YES");
else
puts("NO");
}
return 0;
}```

B - Two Buttons
n变到m，要么乘以2，要么减去1，的最小步数。简单bfs

```#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
const int inf = 0x3f3f3f3f;

int n, m;

struct nod{
int x, s;
};
int vis[100010];

queue <nod> q;

int bfs( int st, int ed )
{
while( !q.empty() )
q.pop();
memset( vis, 0, sizeof( vis ) );
nod t;
t.x = st, t.s = 0;
vis[st] = 1;
q.push( t );
while( !q.empty() )
{
nod now = q.front();
q.pop();
if( now.x == ed )
{
return now.s;
}
nod nxt;
nxt.s = now.s + 1;
if( !vis[ now.x << 1] && ( now.x << 1 ) <= 10000 )//注意不能超过范围
{
nxt.x = now.x << 1;
q.push( nxt );
vis[nxt.x] = 1;
}
if( !vis[ now.x - 1 ] )
{
nxt.x = now.x - 1;
if( nxt.x < 0 )
continue;
q.push( nxt );
vis[nxt.x] = 1;
}
}
}

int main()
{
while( ~scanf("%d%d", &n, &m))
{
if( n <= 0 )
{
cout << "0" << endl;
continue;
}
if( m <= n )
{
printf("%d\n", n - m);
continue;
}
int ans = bfs( n, m );
cout << ans << endl;
}
return 0;
}```

C - DNA Alignment
h函数是两个相同长度的字符串，在同位置相同字符的数量，p函数是循环移位后得到的总和，然后给出S串求使p函数最大的T串有几个。

```#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
const int mod = 1e9 + 7;
typedef long long LL;
typedef pair <int, int> PLL;

char str[100110];
int num[100];

int main ()
{
int n;
while (~scanf("%d", &n))
{
int maxs = 0;
scanf("%s", str);
memset (num, 0, sizeof(num));
for (int i = 0; i < n; ++i)
{
++num[str[i]];
maxs = max (maxs, num[str[i]]);
}
int cnt = 0;
if (num['A'] == maxs)
{
++cnt;
}
if (num['G'] == maxs)
{
++cnt;
}
if (num['T'] == maxs)
{
++cnt;
}
if (num['C'] == maxs)
{
++cnt;
}
LL ans = 1;
for (int i = 1; i <= n; ++i)
{
ans *= (LL)cnt;
ans %= mod;
}
cout << ans << endl;
}
return 0;
}```