第十七届浙大城市学院程序设计竞赛水题

Powered by:AB_IN 局外人

A Sumo and Keyboard-Cat

while True:
    try:
        s=input()
        cnt=0
        if s[0].islower():
            cnt+=1
        for i in range(len(s)-1):
            if s[i].isupper()==True and s[i+1].isupper()==True:
                continue
            if s[i].islower()==True and s[i+1].islower()==True:
                continue
            cnt+=1
        print(cnt)
    except:
        break

B Sumo and His Followers

#include 
#pragma GCC optimize(2)
#pragma GCC optimize(3)
typedef unsigned long long ll;
const ll maxn=1e6;
using namespace std;
namespace IO{
    char ibuf[1<<21],*ip=ibuf,*ip_=ibuf;
    char obuf[1<<21],*op=obuf,*op_=obuf+(1<<21);
    inline char gc(){
        if(ip!=ip_)return *ip++;
        ip=ibuf;ip_=ip+fread(ibuf,1,1<<21,stdin);
        return ip==ip_?EOF:*ip++;
    }
    inline void pc(char c){
        if(op==op_)fwrite(obuf,1,1<<21,stdout),op=obuf;
        *op++=c;
    }
    inline int read(){
        register int x=0,ch=gc(),w=1;
        for(;ch<'0'||ch>'9';ch=gc())if(ch=='-')w=-1;
        for(;ch>='0'&&ch<='9';ch=gc())x=x*10+ch-48;
        return w*x;
    }
    template<class I>
    inline void write(I x){
        if(x<0)pc('-'),x=-x;
        if(x>9)write(x/10);pc(x%10+'0');
    }
    class flusher_{
    public:
        ~flusher_(){if(op!=obuf)fwrite(obuf,1,op-obuf,stdout);}
    }IO_flusher;
}
ll a[maxn],n,m,t;
int main()
{
    using namespace IO;
    t=read();
    while(t--){
    n=read();
    for(ll i=1;i<=n;i++)  a[i]=read();
    sort(a+1,a+n+1);
    ll sum=0;
    for(ll i=1;i<=n;i++)  sum+=(n-i)*a[i];
    printf("%.2lf\n",1.0*sum/n);
    }
}

在这里插入图片描述
不小心 搞了个耗时最少。。

  1. 贪心算法:既然排队时间要最短,那么就让等待时间短的排在前面。
  2. 读入输出模板
namespace IO{
    char ibuf[1<<21],*ip=ibuf,*ip_=ibuf;
    char obuf[1<<21],*op=obuf,*op_=obuf+(1<<21);
    inline char gc(){
        if(ip!=ip_)return *ip++;
        ip=ibuf;ip_=ip+fread(ibuf,1,1<<21,stdin);
        return ip==ip_?EOF:*ip++;
    }
    inline void pc(char c){
        if(op==op_)fwrite(obuf,1,1<<21,stdout),op=obuf;
        *op++=c;
    }
    inline int read(){
        register int x=0,ch=gc(),w=1;
        for(;ch<'0'||ch>'9';ch=gc())if(ch=='-')w=-1;
        for(;ch>='0'&&ch<='9';ch=gc())x=x*10+ch-48;
        return w*x;
    }
    template<class I>
    inline void write(I x){
        if(x<0)pc('-'),x=-x;
        if(x>9)write(x/10);pc(x%10+'0');
    }
    class flusher_{
    public:
        ~flusher_(){if(op!=obuf)fwrite(obuf,1,op-obuf,stdout);}
    }IO_flusher;
} 
const int maxn=100005;

这个读入输出可太快了。。。
用时就using namespace IO即可,putchar 变成了pc

  1. 如果要最后变成double型的变量,一开始声明和之前变量相同的类型。到最后用printf("%lf",1.0*x)输出,乘1.0转化成浮点型。

F Sumo and Luxury Car

找规律快速幂即可。

#include 
typedef unsigned long long ll;
const ll mod=1e9+7;
using namespace std;
namespace IO{
    char ibuf[1<<21],*ip=ibuf,*ip_=ibuf;
    char obuf[1<<21],*op=obuf,*op_=obuf+(1<<21);
    inline char gc(){
        if(ip!=ip_)return *ip++;
        ip=ibuf;ip_=ip+fread(ibuf,1,1<<21,stdin);
        return ip==ip_?EOF:*ip++;
    }
    inline void pc(char c){
        if(op==op_)fwrite(obuf,1,1<<21,stdout),op=obuf;
        *op++=c;
    }
    inline int read(){
        register int x=0,ch=gc(),w=1;
        for(;ch<'0'||ch>'9';ch=gc())if(ch=='-')w=-1;
        for(;ch>='0'&&ch<='9';ch=gc())x=x*10+ch-48;
        return w*x;
    }
    template<class I>
    inline void write(I x){
        if(x<0)pc('-'),x=-x;
        if(x>9)write(x/10);pc(x%10+'0');
    }
    class flusher_{
    public:
        ~flusher_(){if(op!=obuf)fwrite(obuf,1,op-obuf,stdout);}
    }IO_flusher;
}
ll quickmod (ll a, ll b ,ll c)
{
    ll ret=1%c;
    while(b){
        if(b&1)
            ret=ret*a%c;
        a=a*a%c;
        b=b>>1;
    }
    return ret;
}
ll t,n;
int main()
{
    using namespace IO;
    t=read();
    while(t--){
        n=read();
        write(1ll*quickmod(2,n-1,mod)*n%mod);pc('\n');
    }
    return 0;
}

L Sumo and Coins

也是找规律的题。

t=int(input())
while t>0:
    t-=1
    n,a,b=map(int,input().strip().split())
    if not n&1:
        print("ALL")
    elif a&1:
        print("UP")
    else:
        print("DOWN")

完结。

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