第十七届浙大城市学院程序设计竞赛(同步赛)

A Sumo and Keyboard-Cat
水题,但是总要wa一次。第一次用string写题目,wa了一发,不知道是为什么,到现在还是没有搞清楚,后来用char数组就过了,奇怪奇怪真奇怪
wa代码:
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,s=0;
    string str;
    cin>>str;
    for(i=0;i<str.length()-1;i++)
    {
        if(i==0)
        {
            if(str[1]>='a'&&str[1]<='z')
            {
                s++;
            }
        }
        else
        {
            if(str[i]>='A'&&str[i]<='Z'&&str[i+1]>='a'&&str[i+1]<='z')
                s++;
            if(str[i+1]>='A'&&str[i+1]<='Z'&&str[i]>='a'&&str[i]<='z')
                s++;
        }
    }
    cout<<s<<endl;
}
char数组代码:
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,s=0;
    string str;
    cin>>str;
    for(i=0;i<str.length()-1;i++)
    {
        if(i==0)
        {
            if(str[1]>='a'&&str[1]<='z')
            {
                s++;
            }
        }
        else
        {
            if(str[i]>='A'&&str[i]<='Z'&&str[i+1]>='a'&&str[i+1]<='z')
                s++;
            if(str[i+1]>='A'&&str[i+1]<='Z'&&str[i]>='a'&&str[i]<='z')
                s++;
        }
    }
    cout<<s<<endl;
}

B Sumo and His Followers
先sort一边然后再用前缀和即可
#include<iostream>
#include<string.h>
#include<algorithm>
typedef long long ll;
using namespace std;
int main()
{
    ll repeat,i;
    cin>>repeat;
    while(repeat--)
    {
        ll n;
        double sum=0;
        cin>>n;
        ll b,a[n];
        double s=0;
        if(n==1)
        {
            cin>>b;
            sum=0.00;
        }
        else
        {
            for(i=0;i<n;i++)
            {
                cin>>a[i];
            }
            sort(a,a+n);
            for(i=1;i<n;i++)
            {
                s+=a[i-1];
                sum+=s;
            }
            sum/=n;
        }
        printf("%.2f\n",sum);
        sum=0;
        s=0;
    }
}

F Sumo and Luxury Car
规律题+快速幂
n->s
1->1
2->4
3->12
4->32
5->80
...
s=n*2^(n-1)
别忘了1e9+7哟
#include<iostream>
#include<algorithm>
typedef unsigned long long ll;
using namespace std;
ll quickpow(ll x,ll y)
{
    ll mod=1000000007;
    ll n=1;
    n%=mod;
    while(y!=0)
    {
        if (y&1!=0) n=n*x%mod;
        y=y>>1;
        x=x*x%mod;
    }
    n%=mod;
    return n;
}
int main()
{
    ll repeat,i;
    scanf("%lld",&repeat);
    while(repeat--)
    {
        ll a;
        cin>>a;
        ll sum=0;
        sum=a*quickpow(2,a-1);
        sum%=1000000007;
        cout<<sum<<endl;
    }
} 
全部评论

相关推荐

做人要有梦想dji:最新工位查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务