水 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. Unable to execute dex: Multiple dex files define

    这是一个编译错误,在ADT的编译器和SDK的工具有差异或是版本不一致时常会出现的一个问题,解决的方案如下: 第一步: updated eclipse (Help->Check for updat ...

  2. QEMU-KVM中的多线程压缩迁移技术

    导读 目前的迁移技术,都是通过向QEMUFILE中直接写入裸内存数据来达到传送虚拟机的目的端,这种情况下,发送的数据量大,从而会导致更高的迁移时间(total time)和黑宕时间(downtime) ...

  3. ruby开发过程中的小总结

    (1)建表的时候注意保留字 在新建的表里无法插入一列的值, 报错信息是:Can't mass-assign protected attributes,这一列的列名是type,查了一下发现是因为type ...

  4. windows下的文件到linux下乱码 iconv 修改文件编码

    conv [选项...] [文件...] 有如下选项可用: 输入/输出格式规范:-f, --from-code=名称 原始文本编码-t, --to-code=名称 输出编码 信息:-l, --list ...

  5. tomcat配置文件之Server.xml

    Server.xml包含的元素有<Server>.<Service>.<Connector>.<Engine>.<Host>.<Con ...

  6. 谷歌浏览器 DEV Tools

    谷歌浏览器如今是Web开发者们所使用的最流行的网页浏览器.伴随每六个星期一次的发布周期和不断扩大的强大的开发功能,Chrome变成了一个必须的工具.大多数可能熟悉关于chorme的许多特点,例如使用c ...

  7. HDOJ 1272 并查集

    小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  8. spring3.2.8+quartz2.2.0(比较全,对比quartz1.x的配置)

    spring3.2.8 + quartz2.2.0报错: java.lang.IncompatibleClassChangeError: class org.springframework.sched ...

  9. MySQL入门书籍和方法分享

    本文罗列了一些适用于MySQL及运维入门和进阶使用的书籍. 背景:各大论坛上总是有很多同学咨询想学习数据库,或者是为入行DBA做些准备.几年来作为一个MySQL DBA的成长过程有一些积累和感悟,特此 ...

  10. OC内存管理--zombie对象

    当我们对于内存进行手动管理的时候,会出现两种错误:一种是野指针错误,一种则为内存泄露.这两点也是我们去管理内存时最终要解决的问题. 内存泄漏是指:不在使用的对象,一直保留在内存中未被销毁,一直占有着内 ...