水 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. PHP生成CSV文件

    CSV文件的定义这里就不多做介绍了,难能可贵的是用Excel可以直接打开CSV文件.用PHP输出CSV文件本身很简单,但是大家如果有业务需求,下面的代码可以作为参考. $tableheader = a ...

  2. Sqli-LABS通关笔录-1

    在第一个关卡当中还是学到些知识. 1.注释语句多试试其他的几个 2.不报错可能是前面的语句没有错误,union没有得到执行. http://127.0.0.1/sql/Less-1/index.php ...

  3. hiho #1272 买零食 [Offer收割]编程练习赛2

    #1272 : 买零食 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho很喜欢在课间去小卖部买零食.然而不幸的是,这个学期他又有在一教的课,而一教的小卖部姐姐以冷若冰 ...

  4. #!/bin/bash

    #!/bin/bash是指此脚本使用/bin/bash来解释执行. 其中,#!是一个特殊的表示符,其后,跟着解释此脚本的shell路径. bash只是shell的一种,还有很多其它shell,如:sh ...

  5. 【云计算】Docker删除名称为none的Image镜像

    先上删除命令: docker images|grep none|awk '{print $3 }'|xargs docker rmi docker强制批量删除none的image镜像   真是有段时间 ...

  6. POJ 2418

    http://poj.org/problem?id=2418 这是一个二叉树的题目,但我看了下书,还是不是特别理解会用二叉树,所以我就用其他的办法来做,结果一样AC,时间也就1700多ms,比起二叉树 ...

  7. iOS 中使用类别简化代码开发

    最近需要一个函数,把CLLocation对象转化为NSDictionary,按照我以前的想法,我会写一个工具类,之后添加一个函数,类似这样 - (NSDictionary *)turnLocation ...

  8. Java for LeetCode 029 Divide Two Integers

    Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...

  9. 22.python笔记之web框架

    一.web框架本质 1.基于socket,自己处理请求 #!/usr/bin/env python3 #coding:utf8 import socket def handle_request(cli ...

  10. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...