Codeforces Round #295 (Div. 2)
/*
水题
*/
#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)的更多相关文章
- 【记忆化搜索】Codeforces Round #295 (Div. 2) B - Two Buttons
题意:给你一个数字n,有两种操作:减1或乘2,问最多经过几次操作能变成m: 随后发篇随笔普及下memset函数的初始化问题.自己也是涨了好多姿势. 代码 #include<iostream> ...
- codeforces 521a//DNA Alignment// Codeforces Round #295(Div. 1)
题意:如题定义的函数,取最大值的数量有多少? 结论只猜对了一半. 首先,如果只有一个元素结果肯定是1.否则.s串中元素数量分别记为a,t,c,g.设另一个串t中数量为a',t',c',g'.那么,固定 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #295 (Div. 1) C. Pluses everywhere
昨天ZZD大神邀请我做一道题,说这题很有趣啊. 哇,然后我被虐了. Orz ZZD 题目大意: 你有一个长度为n的'0-9'串,你要在其中加入k个'+'号,每种方案就会形成一个算式,算式算出来的值记做 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Hadoop 免密码登陆(ssh)
record save here first [root@hadoop .ssh]# ssh-keygen -t rsa -P ''Generating public/private rsa key ...
- UISerachBar / UISearchDisplayController
1. UISerachBar 继承与UIView, 包含uitextfield, 并且实现了uitextfielddelegate代理的主要内容 含有取消按钮, 默认不显示 2. UISerachDi ...
- ReactiveCocoa入门教程:第一部分
http://www.cocoachina.com/ios/20150123/10994.html 本文翻译自RayWenderlich,原文:ReactiveCocoa Tutorial--The ...
- 在html中注释对 <include XXXXXXXX />是没有影响的
在html中注释对 <include XXXXXXXX />是没有影响的
- VS2008+Qt+助手 智能提示不显示、Qt关键字不高亮的解决办法【已解决】
笔者使用的开发环境是VS2008+Qt4.8.5+VAssistX,有时候会出现代码关键字不能高亮显示,并且助手的智能提示不显示.问题如下 解决的办法是在助手的选项中设置其搜索路径,助手的设置通过VS ...
- Leetcode 之Construct Binary Tree(52)
根据先序和中序构造二叉树.根据中序和后序构造二叉树,基础题,采用递归的方式解决,两题的方法类似.需要注意的是迭代器的用法. //先序和中序 TreeNode *buildTree(vector< ...
- HTML快速入门4
七.表单 1. 概述 建立交互式的站点,需要使用 HTML 表单,它可以让用户提供信息,并对此作出处理.可以建立类似 复选框.单选按钮及文本框的控件. 掌握表单的使用对 Active Server P ...
- The CompilerVersion constant identifies the internal version number of the Delphi compiler.
http://delphi.wikia.com/wiki/CompilerVersion_Constant The CompilerVersion constant identifies the in ...
- 2015安徽省赛 A.First Blood
题目描述 盖伦是个小学一年级的学生,在一次数学课的时候,老师给他们出了一个难题: 老师给了一个正整数 n,需要在不大于n的范围内选择三个正整数(可以是相同的),使它们三个的最小公倍数尽可能的大.盖伦很 ...
- 07 DAY 1
壮烈的一天... 第一题 本意是水题,然后写了块状数组模拟,最后发现算法错了... 然后其实快排一遍扫一遍完事... 100分 #include <cstdio> #include < ...