水 A. Pangram

/*
水题
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <string>
#include <cstring>
using namespace std; int main(void)
{
//freopen ("A.in", "r", stdin); map<char, int> m1;
map<char, int> 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 B. Two Buttons

题意:给出n,m两个数字,n可以*2,或者-1,问最少几步n变成m
思路:BFS:从n出发,分两条路(a, b),标记计算后的数字,如果没找到,入队;如果找到了则输出,不入队,BFS结束。详细解释

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <string>
#include <cstring>
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<struct NODE> 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;
}

  

Codeforces Round #295 (Div. 2)的更多相关文章

  1. 【记忆化搜索】Codeforces Round #295 (Div. 2) B - Two Buttons

    题意:给你一个数字n,有两种操作:减1或乘2,问最多经过几次操作能变成m: 随后发篇随笔普及下memset函数的初始化问题.自己也是涨了好多姿势. 代码 #include<iostream> ...

  2. codeforces 521a//DNA Alignment// Codeforces Round #295(Div. 1)

    题意:如题定义的函数,取最大值的数量有多少? 结论只猜对了一半. 首先,如果只有一个元素结果肯定是1.否则.s串中元素数量分别记为a,t,c,g.设另一个串t中数量为a',t',c',g'.那么,固定 ...

  3. Codeforces Round #295 (Div. 2)C - DNA Alignment 数学题

    C. DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  4. Codeforces Round #295 (Div. 2)B - Two Buttons BFS

    B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  5. Codeforces Round #295 (Div. 2)A - Pangram 水题

    A. Pangram time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  6. Codeforces Round #295 (Div. 1) C. Pluses everywhere

    昨天ZZD大神邀请我做一道题,说这题很有趣啊. 哇,然后我被虐了. Orz ZZD 题目大意: 你有一个长度为n的'0-9'串,你要在其中加入k个'+'号,每种方案就会形成一个算式,算式算出来的值记做 ...

  7. Codeforces Round #295 (Div. 2)---B. Two Buttons( bfs步数搜索记忆 )

    B. Two Buttons time limit per test : 2 seconds memory limit per test :256 megabytes input :standard ...

  8. Codeforces Round #295 (Div. 2) B. Two Buttons

    B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  9. Codeforces Round #295 (Div. 2) B. Two Buttons 520B

    B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. 修改织梦默认提示"dedecms提示信息!"

    在使用dedecms搜索的时候如果搜索频率过快,经常会跳出一个提示窗口提示"管理员设定搜索时间间隔为*秒,请稍后再试!".怎么自定义Dedecms提示信息呢?让心存不轨的家伙少一个 ...

  2. Xcode 4.6.3 Bug - .m 文件不能正常打开,uitableveiwController

    当打开.m文件时尤其是自定义的继承uitableviewcontroler的m 文件.不能滑动,不能正常显示. 解决方法: 用文本编辑器打开这个文件,关闭xcode .然后在继承uitableview ...

  3. MySQL 5.6 Warning: Using a password on the command line interface can be insecure

    MySQL 5.6 在命令行输入密码,就会提示这些安全警告信息. Warning: Using a password on the command line interface can be inse ...

  4. tomcat安全配置(二)

    1. JVM 1.1. 使用 Server JRE 替代JDK. 服务器上不要安装JDK,请使用 Server JRE. 服务器上根本不需要编译器,代码应该在Release服务器上完成编译打包工作. ...

  5. Python获取目录、文件的注意事项

    Python获取指定路径下的子目录和文件有两种方法: os.listdir(dir)和os.walk(dir),前者列出dir目录下的所有直接子目录和文件的名称(均不包含完整路径),如 >> ...

  6. Group Shifted Strings

    Given a string, we can "shift" each of its letter to its successive letter, for example: & ...

  7. 1.7 逆序数与归并排序[inversion pairs by merge sort]

    [本文链接] http://www.cnblogs.com/hellogiser/p/inversion-pairs-by-merge-sort.html [题目] 编程之美1.7光影切割问题可以进一 ...

  8. canvas API ,通俗的canvas基础知识(二)

    上文我们讲到了画一条线,画矩形,写文字,总算是有了一个好的开头,如果还没有看的同学出门左转,先看看那篇,这里就不多做叙述了,接下来我们看比较复杂的一些属性和方法! 讲之前呢,我还是想温习一下,毕竟上文 ...

  9. windows电脑变成wifi热点命令

    netsh wlan set hostednetwork mode=allow ssid=WIFI_NAME key="abcdefgh" netsh wlan start hos ...

  10. ajax(ajax开发与入门)

    AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术.AJAX是一种进行页面局部异步刷新的技术,局 ...