JSCPC补题

B. Higher h-index
The h-index of an author is the largest h where he has at least h papers with citations not less than h.
Bobo has no papers and he is going to publish some subsequently. If he works on a paper for x hours, the
paper will get (a · x) citations, where a is a known constant. It’s clear that x should be a positive integer.
There is also a trick – one can cite his own papers published earlier.
Given Bobo has n working hours, find the maximum h-index of him.

Input
The input consists of several test cases and is terminated by end-of-file.
Each test case contains two integers n and a.

Output
For each test case, print an integer which denotes the maximum h-index.
Constraint
• 1 <= n <= 1e9
• 0 <= a <= n
• The number of test cases does not exceed 104.

Sample Input
3 0
3 1
1000000000 1000000000

Sample Output
12
1000000000

Note
For the first sample, Bobo can work 3 papers for 1 hour each. With the trick mentioned, he will get papers
with citations 2, 1, 0. Thus, his h-index is 1.
For the second sample, Bobo can work 2 papers for 1 and 2 hours respectively. He will get papers with
citations 1 + 1, 2 + 0. Thus, his h-index is 2.

这题巨坑,一定要读懂题,而且,不要相信Note,这是一个坑。通过很久的推导,我们可以发现一个小时一个小时地发论文,最后的h-index可以得到最大,而且,最后可以化简成一条公式,(a+n)/2 。

代码

#include<bits/stdc++.h>
using namespace std ;

int main()
{
    long long n , a ;
    while(cin >> n >> a)
        cout << (a+n)/2 << endl;
    return 0 ;
}

G. String Transformation
Bobo has a string S = s1s2 … sn consists of letter a, b and c. He can transform the string by inserting or
deleting substrings aa, bb and abab.
Formally, A = u  w  v (“” denotes string concatenation) can be transformed into A0 = u  v and vice versa
where u, v are (possibly empty) strings and w 2 {aa, bb, abab}.
Given the target string T = t1t2 … tm, determine if Bobo can transform the string S into T.

Input
The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains a string s1s2 … sn. The second line contains a string t1t2 … tm.

Output
For each test case, print Yes if Bobo can. Print No otherwise.
Constraint
• 1  n,m  104
• s1, s2, … , sn, t1, t2, … , tm 2 {a, b, c}
• The sum of n and m does not exceed 250, 000.

Sample Input
ab
ba
ac
ca
a
ab

Sample Output
Yes
No
No

Note
For the first sample, Bobo can transform as ab => aababb => babb => ba.

题意是,我们可以在一个字符串中添加或者删除 aa,bb,abab(而且,字符串中只含有a,b,c,三种字符),最后是否可以得到所需要的字符串。

通过分析,我们可以知道,c的个数和相对位置是不变的,a,b的个数是有对应关系,初始的a是奇数,变化后还是奇数,初始a是偶数,变化后还是偶数,b同理。
于是,我们可以以c为分界点,分别统计c前后a,b的数量,然后跟目标字符串的数量进行比较

代码

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std ;

int a1[10005] ;
int b1[10005] ;
int a2[10005] ;
int b2[10005] ;
int cntc1 = 0 ;
int cntc2 = 0 ;

int main()
{
    ios::sync_with_stdio(false) ;
    string s1, s2 ;
    while(cin >> s1 >> s2)
    {
        memset(a1,0,sizeof(a1)) ;
        memset(a2,0,sizeof(a2)) ;
        memset(b1,0,sizeof(b1)) ;
        memset(b2,0,sizeof(b2)) ;
        int cntc1 = 0 ;
        int i = 0 ;
        while(i < s1.size())
        {
            if(s1[i] == 'c')
            {
                cntc1 ++ ;
            }
            if(s1[i] == 'a')
            {
                a1[cntc1] ++ ;
            }
            if(s1[i] == 'b')
            {
                b1[cntc1] ++ ;
            }
            i ++ ;
        }
        i = 0 ;
        int cntc2 = 0 ;
        while(i < s2.size())
        {
            if(s2[i] == 'c')
            {
                cntc2 ++ ;
            }
            if(s2[i] == 'a')
            {
                a2[cntc2] ++ ;
            }
            if(s2[i] == 'b')
            {
                b2[cntc2] ++ ;
            }
            i ++ ;
        }
        if(cntc1 != cntc2)
        {
            cout << "No" << endl ;
            continue ;
        }
        int flag = 1;
        for(int j = 0 ; j <= cntc1; j ++)
        {
            if(a1[j]%2 != a2[j]%2 || b1[j]%2 != b2[j]%2)
            {
                flag = 0 ;
                cout << "No" << endl ;
                break ;
            }
        }
        if(!flag)
        {
            continue ;
        }
        cout << "Yes"<< endl ;
    }
    return 0 ;
}

猜你喜欢

转载自blog.csdn.net/Lewis_Fehling/article/details/80337166