水 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. 最近打算体验一下discuz,有不错的结构化数据插件

    提交sitemap是每位站长必做的事情,但是提交到哪里,能不能提交又是另外一回事.国内的话百度是大伙都会盯的蛋糕,BD站长工具也会去注册的,可有些账号sitemap模块一直不能用,或许是等级不够,就像 ...

  2. 机器学习公开课笔记(3):Logistic回归

    Logistic 回归 通常是二元分类器(也可以用于多元分类),例如以下的分类问题 Email: spam / not spam Tumor: Malignant / benign 假设 (Hypot ...

  3. Marriage Ceremonies(状态压缩dp)

     Marriage Ceremonies Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  4. C语言可以包含.txt文件

    // fa.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"#include "iostream"#include" ...

  5. Stanford机器学习---第二讲. 多变量线性回归 Linear Regression with multiple variable

    原文:http://blog.csdn.net/abcjennifer/article/details/7700772 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...

  6. Longest Substring with At Most K Distinct Characters

    Given a string, find the longest substring that contains only two unique characters. For example, gi ...

  7. POJ 3083

    ---恢复内容开始--- http://poj.org/problem?id=3083 题目大意就是给你要你从S走到E,且只有.代表的地方才是可以走的,有三种方式的走法. 一.是向左优先转,从S到E的 ...

  8. Android 调用浏览器和嵌入网页

    Android App开发时由于布局相对麻烦,很多时候一个App通常是由html5和原生控件相结合而成.简单的网页应用可以直接内嵌html5页面即可,对于需要调用复杂的底层功能时则采用原生控件的方式进 ...

  9. Android 中“TabBar”的背景拉伸问题

    在最近的一个工程中,要求有一个在上方了tabbar,上面有并排的3个方形按钮,每个按钮都有背景图.问题来了,如何让图片在不同尺寸的屏幕上不失真呢?(由于我们的项目比较小,工时很短,不能为每一个屏幕尺寸 ...

  10. canvas API ,通俗的canvas基础知识(四)

    今天要讲的内容是canvas的转换功能,前面的内容没用看的同学可以出门右转,先看看前面的基础知识,废话不多说,开始进入正题吧! 何为转换功能?熟悉css3的同学都知道,css3里面有transform ...