Codeforcfes #round461 div.2

    真正的修仙场,本来是订在12:35的后来调到了1:15,勉强熬着打完。题面比较短,对阅读要求还比较低,废话不多说看一下题目。

     A. Cloning Toys
    
        题目大意:Imp这个小屁孩呢特别喜欢他的玩具,有一天他找到一个可以克隆玩具的机器,这个机器有两种克隆方式,第一种是放入一个原件,可以获得一个原件和一个附件,第二种是放入一个附件得到两个附件;问给出最终的原件和附件的数量能否通过多次克隆操作得到,如果可以输出Yes,如果不行输出No;(注:原先持有一个原件)
        题解:我们假设经过了N次第一种操作,M次第二种操作,可以得到X=N+1,Y=N+2M;很容易得到X,Y之间的关系为(Y+1-X)%2=0,于是我们把它作为我们的一个判断条件,其次是当M为0时,X=Y-1;当N=0时,Y=M=0。
               这个题目其实思路十分简单,但是要非常注意细节,特殊值的处理是Hack点(被Hack两次,超级痛心);

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long

using namespace std;

int main()
{
    int n,m;
    scanf("%d%d",&m,&n);
    if(n<=0||m<0)
    {
        printf("No\n");
        return 0;
    }
    if(n==1&&m!=0)
    {
        printf("No\n");
        return 0;
    }
    if(m<n-1)
    {
        printf("No\n");
        return 0;
    }
    if((m-n+1)%2==0)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


    题目大意:给你一个范围N,请问长度小于N的三条边A,B,C能组成多少种非退化的三角形(即面积不为0),同时三条边A,B,C满足条件A^B^C=0;
        题解:观察N的数据范围是1到2500,所以开三重循环的枚举肯定是不科学的,所幸我们要找的第三条边可以通过对另外两条边的枚举直接得出第三边,然后进行比较即可。先做一个预处理出当最长边为i时的情况,在累加起来即可,没什么坑点。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long

using namespace std;
int cnt[2600];
int sum[2600];
int main()
{
    for(int i=1;i<=2500;i++)
        for(int j=1;j<=i;j++)
    {
        int k=(i^j);
        if(k<=0)
            continue;
        if(k<=j&&j+k>i)
        {
            cnt[i]++;
        }
        else
            continue;
    }
    sum[1]=0;
    for(int i=1;i<=2500;i++)
    {
        sum[i]=sum[i-1]+cnt[i];
    }
    int n;
    while(~scanf("%d",&n))
    {
        printf("%d\n",sum[n]);
    }
    return 0;
}



C. Cave Painting
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Imp is watching a documentary about cave painting.

Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1 to k. Unfortunately, there are too many integers to analyze for Imp.

Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all , 1 ≤ i ≤ k, are distinct, i. e. there is no such pair (i, j) that:

  • 1 ≤ i < j ≤ k,
  • , where is the remainder of division x by y.
Input

The only line contains two integers n, k (1 ≤ n, k ≤ 1018).

Output

Print "Yes", if all the remainders are distinct, and "No" otherwise.

You can print each letter in arbitrary case (lower or upper).

Examples
Input
4 4
Output
No
Input
5 3
Output
Yes
Note

In the first sample remainders modulo 1 and 4 coincide.

        题目大意:给你两个数,n和k,问你他们是否满足条件:n对i(1<=i<=k)取模的结果均不相同。满足输出Yes,否则输出No;
           题解:不得不说是个很有趣的题,其实只要你仔细想一下,就会发现一件有趣的事情,对1取模的余数只有一种可能,对2有两种,以此类推,对k有k-1中。而我们又要去所得余数各不相同,那么不难发现对1取模的结果必须是0,对2必须是1,对k必须是k-1……,虽然k的数据范围是1e17,但是从1开始一直到1000足以包括n的数据范围(1e17)。代码极其短。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long

using namespace std;

int main()
{
    ll n,m;
    scanf("%I64d%I64d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        if(n%i!=(i-1))
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}



D. Robot Vacuum Cleaner
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pushok the dog has been chasing Imp for a few hours already.

Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner.

While moving, the robot generates a string t consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string t as the number of occurrences of string "sh" as a subsequence in it, in other words, the number of such pairs (i, j), that i < j and and .

The robot is off at the moment. Imp knows that it has a sequence of strings ti in its memory, and he can arbitrary change their order. When the robot is started, it generates the string t as a concatenation of these strings in the given order. The noise of the resulting string equals the noise of this concatenation.

Help Imp to find the maximum noise he can achieve by changing the order of the strings.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of strings in robot's memory.

Next n lines contain the strings t1, t2, ..., tn, one per line. It is guaranteed that the strings are non-empty, contain only English letters 's' and 'h' and their total length does not exceed 105.

Output

Print a single integer — the maxumum possible noise Imp can achieve by changing the order of the strings.

Examples
Input
4
ssh
hs
s
hhhs


Output
18
Input
2
h
s
Output
1

Note

The optimal concatenation in the first sample is ssshhshhhs.

   题目大意:给你n个字符串,请你将它们串起来,使得sh最多,只要s在前h在即可算为一个(例如:ssh含两个,sshsh喊2+3=5个),输出这个数量。
            题解:贪心思想进行排序然后连接起来即可。(注意数据范围,需要开long long int)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=1e5+10;
struct Str
{
    string s;
    double cnt;
}S[maxn];
static bool cmp(const Str& str1,const Str& str2)
{
	return str1.cnt>str2.cnt;
}

string findSmallest(Str S[], int n)
{
	string str = "";
	sort(S+1,S+n+1,cmp);
	for (int i=1;i<=n; ++i)
		str+=S[i].s;
	return str;
}

int main()
{
    int n;
    string N;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        cin>>S[i].s;
    }
    for(int i=1;i<=n;i++)
    {
        int is=0,ih=0;
        for(int j=0;S[i].s[j]!='\0';j++)
        {
            if(S[i].s[j]=='s')
                is++;
            else
                ih++;
        }
        if(ih==0)
            S[i].cnt=INF;
        else
            S[i].cnt=(double)is/double(ih);
    }
    N=findSmallest(S,n);
    int s=0,h=0;
    if(N[0]=='s')
        s++;
    else
        h++;
    ll sum=0;
    for(int i=1;N[i]!='\0';i++)
    {
        if(N[i]=='s')
            s++;
        else
        {
            h++;
            sum+=s;
        }
    }
    printf("%I64d\n",sum);
    return 0;
}

可惜最后D题刚做完就到时间了,很气。后面两道题有时间会慢慢补上,大致就先到这里。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值