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  ith  bird stands on the top of the  ith  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]

1n,m1000000(106)

1h[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;
}











你可能感兴趣的:(ACM,HDU)