1. 程式人生 > >Codeforces Round #295 (Div. 2) ABC

Codeforces Round #295 (Div. 2) ABC

A - Pangram :判斷一個字串中有木有出現過26個字母,不論大小寫,有YES沒有NO

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
const int inf = 0x3f3f3f3f;

char a[1000];
int cnt;
int vis[30];

int main()
{
    int n;
    while( ~scanf("%d", &n ))
    {
        scanf("%s", a);
        if( n < 26 )
        {
            cout << "NO" << endl;
            continue;
        }
        cnt = 0;
        int len = strlen( a );
        memset( vis, 0, sizeof( vis ));
        for( int i = 0; i < len; i++ )
        {
            if( a[i] <= 'z' && a[i] >= 'a' )
            {
                if( !vis[ a[i] - 'a' ] )
                {
                    cnt++;
                    vis[ a[i] -'a' ] = 1;
                }
            }
            else
            {
                if( !vis[ a[i] - 'A'] )
                {
                    cnt++;
                    vis[ a[i] - 'A' ] = 1;
                }
            }
        }
        if( cnt == 26 )
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}
B - Two Buttons  n變到m,要麼乘以2,要麼減去1,的最小步數。簡單bfs
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
const int inf = 0x3f3f3f3f;

int n, m;

struct nod{
    int x, s;
};
int vis[100010];

queue <nod> q;

int bfs( int st, int ed )
{
    while( !q.empty() )
        q.pop();
    memset( vis, 0, sizeof( vis ) );
    nod t;
    t.x = st, t.s = 0;
    vis[st] = 1;
    q.push( t );
    while( !q.empty() )
    {
        nod now = q.front();
        q.pop();
        if( now.x == ed )
        {
            return now.s;
        }
        nod nxt;
        nxt.s = now.s + 1;
        if( !vis[ now.x << 1] && ( now.x << 1 ) <= 10000 )//注意不能超過範圍
        {
            nxt.x = now.x << 1;
            q.push( nxt );
            vis[nxt.x] = 1;
        }
        if( !vis[ now.x - 1 ] )
        {
            nxt.x = now.x - 1;
            if( nxt.x < 0 )
                continue;
            q.push( nxt );
            vis[nxt.x] = 1;
        }
    }
}

int main()
{
    while( ~scanf("%d%d", &n, &m))
    {
        if( n <= 0 )
        {
            cout << "0" << endl;
            continue;
        }
        if( m <= n )
        {
            printf("%d\n", n - m);
            continue;
        }
        int ans = bfs( n, m );
        cout << ans << endl;
    }
    return 0;
}

C - DNA Alignment h函式是兩個相同長度的字串,在同位置相同字元的數量,p函式是迴圈移位後得到的總和,然後給出S串求使p函式最大的T串有幾個。

首先得到T串裡的字元就是S裡面字元出現最多的字元,當有多個字元出現次數一樣的話,那麼該位置填哪個都沒關係了,又因為有n位,所以最後結果就是出現的最大次數的字母的^n

#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
const int mod = 1e9 + 7;
typedef long long LL;
typedef pair <int, int> PLL;

char str[100110];
int num[100];

int main ()
{
    int n;
    while (~scanf("%d", &n))
    {
        int maxs = 0;
        scanf("%s", str);
        memset (num, 0, sizeof(num));
        for (int i = 0; i < n; ++i)
        {
            ++num[str[i]];
            maxs = max (maxs, num[str[i]]);
        }
        int cnt = 0;
        if (num['A'] == maxs)
        {
            ++cnt;
        }
        if (num['G'] == maxs)
        {
            ++cnt;
        }
        if (num['T'] == maxs)
        {
            ++cnt;
        }
        if (num['C'] == maxs)
        {
            ++cnt;
        }
        LL ans = 1;
        for (int i = 1; i <= n; ++i)
        {
            ans *= (LL)cnt;
            ans %= mod;
        }
        cout << ans << endl;
    }
    return 0;
}


相關推薦

Codeforces Round #295 (Div. 2) ABC

A - Pangram :判斷一個字串中有木有出現過26個字母,不論大小寫,有YES沒有NO #include <map> #include <set> #include <queue> #include <stack> #i

Codeforces Round #295 (Div. 2)

mes pie The san oat position out float transform B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes inp

Codeforces Round #500 (Div. 2) ABC

end strong out != with cout ron def include A. Piles With Stones 水題略 B. And 題意:讓輸入一個n,一個下,之後輸入一個長為n的數組a,可以在a中使a變為a&x,問經過幾次變化數組中有相同的

Codeforces Round #524 (Div. 2) ABC

A - Petya and Origami 題意:n個客人,每個本子有m張同一顏色的紙; 每一個客人要 紅色2張 綠色5張  白色8張; 問最少需要買多少本本子   #include<bits/stdc++.h> using namespace s

Codeforces Round #525 (Div. 2)ABC總結

菜,手速不行,三題掛機,rank900+,掉了7分。。。 A:找兩個數,a,b,滿足題中所給的要求。隨便暴力就行,最簡單的寫法是n=1就是-1,否則輸出倆n。 B:給你n個數,每次輸出最小的那個數,然後把所有數減去這個數,問你m次操作取出的數是多少。 由於不能重複,用一個set存,然後一

Codeforces Round #366 (Div. 2) ABC

A I hate that I love that I hate it水題 1 #I hate that I love that I hate it 2 n = int(raw_input()) 3 s = "" 4 a = ["I hate that ","I love that ",

Codeforces Round #532 (Div. 2) ABC解題報告

GG,又是掉分場,5分鐘才進去網站,然後A題提交頁面又花了10多分鐘,等交上的時候已經20分鐘了。。。 B題題意不明,WA了兩發。C題真tm坑,推個破公式推對了還沒寫對,然後就想別的公式去了,等過的時候已經過了2000+人了。。。 好在最後沒掛終測。(心疼兩道題掛終測的隊友三秒) A:給

Codeforces Round #295 (Div. 2) E

Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote outnnumbers on a single line. After that, Vasya began

Codeforces Round #548 (Div. 2) ABC 題解

tor cin %d color scanf ems event bstr esp 題目鏈接 A. Even Substrings 分析 當輸入第i個數的時候,判斷一下是不是偶數,若是偶數的話ans+=i,以這個數為r的子串有i個,最後統計出來的ans就是答案. 代

Codeforces Round #556 (Div. 2)-ABC(這次的題前三題真心水)

getchar hal tdi pac char prim img end rime A. Stock Arbitraging 直接上代碼: #include<cstdio> #include<cstring> #include<

Codeforces Round #185 (Div. 2)(解題報告)(ABC出DE補)

第一次抽時間做一整套的cf ,可以說是心情複雜,D,E都是什麼神仙題目啊!!! A   Whose sentence is it? (水題) 題目: One day, liouzhou_101 got a chat record of Freda and Rain

Codeforces Round #221 (Div. 2) D

cpp 位置 input memset ont code init cal 矩形 有點郁悶的題目,給了2000ms,可是n,m的範圍已經是5000了。5000 * 5000一般在別的OJ已經是超了2000ms,一開始不敢敲。看了下別人有n*m的潛逃循環,原來CF的機子如

2017-5-2-Train:Codeforces Round #323 (Div. 2)

width ins exp seq main ons mon tel exists A. Asphalting Roads(模擬) City X consists of n vertical and n horizontal infinite roads, forming

Codeforces Round #414 Div.2

span main pre style namespace one ret == hide A 膜你 1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 5

Codeforces Round #365 (Div. 2) D - Mishka and Interesting sum(離線樹狀數組)

turn string 之前 algorithm printf ace r++ void contest http://codeforces.com/contest/703/problem/D 題意: 給出一行數,有m次查詢,每次查詢輸出區間內出現次數為偶數次的數字的異

Codeforces Round #271 (Div. 2) D. Flowers (遞推 預處理)

int art style eve itl which pop 有一種 esp We saw the little game Marmot made for Mole‘s lunch. Now it‘s Marmot‘s dinner time and, as we

Codeforces Round #406 (Div. 2) E. Till I Collapse(主席樹)

esp type 個數 gif lan upd roo node .com 題目鏈接:Codeforces Round #406 (Div. 2) E. Till I Collapse 題意: 給你n個數,對於每一個k(1<=k<=n),劃分區間,每個區間只能有

Codeforces Round #Pi (Div. 2) (STL專場)

type ef7 ogre space each redo 長度 lang max Codeforces Round #Pi (Div. 2) A - Lineland Mail 水題,拼手速。 /* * @author Novicer * language :

Codeforces Round #416 (Div. 2) A+B

src separate not sum redo swe tput output depend A. Vladik and Courtesy 2 seconds 256 megabytes At regular competition Vl

Codeforces Round #415 (Div. 2) C. Do you want a date?

for 題目 point system pro only const man test C. Do you want a date? 2 seconds 256 megabytes Leha decided to move to a