HDU - 5198 - Strange Class && 5199 - Gunner

Strange Class

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 74    Accepted Submission(s): 60

Problem Description

In Vivid’s school, there is a strange class(SC). In SC, the students’ names are very strange. They are in the same format: anbncn(a,b,c
must not be the same with each other). For example studens whose names are“abc”,”ddppqq” are in SC, however studens whose names are “aaa”,“ab”,”ddppqqq” are not in SC.

Vivid makes friends with so many students, he wants to know who are in SC.

Input

There are multiple test cases (about 10), each case will give a string S which is the name of Vivid’s friend in a single line.

Please process to the end of file.

[Technical Specification]

1≤|S|≤10.

|S| indicates the length of S.

S only contains lowercase letter.

Output

For each case, output YES if Vivid’s friend is the student of SC, otherwise output NO.

Sample Input

abc
bc

Sample Output

YES
NO

Source

BestCoder Round #36 ($)

很猥琐的一道题

AC代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define INF 0x7fffffff
using namespace std;

char str[350];

int main() {
    while(scanf("%s", str) != EOF) {
        int len = strlen(str);
        if(len <= 2 || len % 3 != 0 || str[0] == str[len - 1]) {
            printf("NO\n");
            continue;
        }

        int a[5] = {0, 0, 0};
        int sum = 0;
        char cur = str[0];
        for(int i = 0; i < len; i++) {
            if(str[i] == cur) a[sum]++;
            else {
                sum++;
                a[sum] ++;
                cur = str[i];
            }
        }

        //printf("%d %d %d %d\n", a[0], a[1], a[2], sum);
        int tmp = len / 3;
        if((len % 3 == 0) && sum == 2 && a[0] == tmp && a[1] == tmp && a[2] == tmp) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

Gunner

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 157    Accepted Submission(s): 85

Problem Description

Long long ago, there is a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There are n birds
and n trees.
The i?th bird
stands on the top of the i?th tree.
The trees stand in straight line from left to the right. Every tree has its height. Jack stands on the left side of the left most tree. When Jack shots a bullet in height H to the right, the bird which stands in the tree with height H will
falls.

Jack will shot many times, he wants to know how many birds fall during each shot.

a bullet can hit many birds, as long as they stand on the top of the tree with height of H.

Input

There are multiple test cases (about 5), every case gives n,m in
the first line, n indicates
there are n trees
and n birds, m means
Jack will shot m times.

In the second line, there are n numbers h[1],h[2],h[3],…,h[n] which
describes the height of the trees.

In the third line, there are m numbers q[1],q[2],q[3],…,q[m] which
describes the height of the Jack’s shots.

Please process to the end of file.

[Technical Specification]

1≤n,m≤1000000(106)

1≤h[i],q[i]≤1000000000(109)

All inputs are integers.

Output

For each q[i],
output an integer in a single line indicates the number of birds Jack shot down.

Sample Input

4 3
1 2 3 4
1 1 4

Sample Output

1
0
1

Hint

Huge input, fast IO is recommended.

Source

BestCoder Round #36 ($)

卡输入,要快速读入,不过貌似不写快速读入也行╮(╯▽╰)╭,心累啊,我还多交了一遍

AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <map>
using namespace std;

int n, m;

inline int readint()
{
    char c = getchar();
    while(!isdigit(c)) c = getchar();  

    int x = 0;
    while(isdigit(c))
    {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}  

int buf[10];
inline void writeint(int i)
{
    int p = 0;
    if(i == 0) {
        p++;
        buf[0] = 0;
    }
    else while(i)
    {
        buf[p++] = i % 10;
        i /= 10;
    }
    for(int j = p-1; j >= 0; j--) putchar('0' + buf[j]);
}  

int main() {
    while(scanf("%d %d", &n, &m) != EOF) {
        map<int, int> mp;
        for(int i = 0; i < n; i++) {
            int t = readint();
            mp[t] ++;
        }

        for(int i = 0; i < m; i++) {
            int t = readint();
            //printf("%d\n", mp[t]);
            writeint(mp[t]);
            putchar(10);
            mp[t] = 0;
        }
    }
    return 0;
}
时间: 2024-08-25 19:19:48

HDU - 5198 - Strange Class && 5199 - Gunner的相关文章

STL HDOJ 5199 Gunner

题目传送门 1 /* 2 题意:问值为x的个数有几个,第二次查询就是0 3 lower/upper_bound ()函数的使用,map也可过,hash方法不会 4 */ 5 #include <cstdio> 6 #include <cmath> 7 #include <cstring> 8 #include <algorithm> 9 #include <iostream> 10 #include <vector> 11 #incl

hdu 1882 Strange Billboard(位运算+枚举)

http://acm.hdu.edu.cn/showproblem.php?pid=1882 感觉非常不错的一道题. 给一个n*m(1<=n,m<=16)的矩阵,每一个格子都有黑白两面,当翻一个格子时,它的上下左右都要翻转,问最后使格子全变为白色的最少翻转步数. 仅仅需枚举第一行的状态即可,由于对于第i(i>=2)行j列翻转情况受上一行的制约,仅仅有当上一行也是'X'的时候,该行j列才干翻转,使i-1行j列变为'.',否则i行j列不能翻转.依次进行下去,当最后一行全变为白色,说明翻转成功

HDU 1882 Strange Billboard(位运算)

题目链接 题意 : 给你一个矩阵,有黑有白,翻转一个块可以让上下左右都翻转过来,问最少翻转多少次能让矩阵变为全白. 思路 : 我们从第一行开始枚举要翻转的状态,最多可以枚举到2的16次方,因为你只要第一行的确定了,第二行要翻转的也就确定了,所以第一行的状态决定了最后的状态.看了网上大神,真是让位运算废了啊,,,,,太复杂了...... 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #

hdu 2899 Strange fuction (二分)

题目链接:http://acm.hdu.edu.cn/showproblem.pihp?pid=2899 题目大意:找出满足F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的x值.注意精确度的问题. 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 using namespace std; 5 double y; 6 7 doub

hdu 5199 Gunner

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5199 简单题,stl水之... 1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<set> 7 #include<map> 8 using std::m

hdu 5199 Gunner(STL之map,水)

Problem Description Long long ago, there is a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There are n birds and n trees. The i−thbird stands on the top of the i−th tree. The trees stand in straight line fr

hdu 5199 Gunner (hash || 排序+二分)

题意:有n个不同高度的树排成一列,树上各有1只鸟. 然后m个询问,每次询问可以打掉h[i](1<=i<=m)高度的所有鸟,问m个询问中的各高度能打掉多少只鸟. 分析: 1.题目给了提示要 “快速读入”  咩~ 2.排序+二分 这里可以两次二分(lower_bound找下界,upper_bound找上界) 也可以合并+二分(合并相同的数字,记录次数) g++提交要用#include<stdio.h> 不要用#include<cstdio> 后者有效率问题,会 tle (⊙

hdoj 5198 Strange Class 水题

Strange Class Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5198 Description In Vivid’s school, there is a strange class(SC). In SC, the students’ names are very strange. They are in the same format: anbncn(a,

hdoj 5199 Gunner map

Gunner Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5199 Description Long long ago, there is a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There are n birds and n