第十七届浙大程序设计竞赛(A&B&F&L)

问题A
题目描述
Sumo家的猫非常喜欢滚键盘,每次Sumo开着电脑离开一小会儿,回来的时候都能在屏幕上看到一串神秘代码。今天,Sumo又得到了这么一串神秘代码。当他盯着屏幕上这串东西沉思的时候,突然发现它只包含大小写英文字母,又想到自己的键盘这几天两个Shift键都坏掉了——也就是说只能通过CAPSLOCK键来切换英文大小写了。于是他很好奇,这次滚键盘的过程中,他家的猫至少摁了几次CAPSLOCK键呢?Sumo记得他刚离开的时候,键盘的大写锁定是开的(也就是说输的是大写字母)。

输入描述:
仅包含一个字符串,表示Sumo家的猫摁出的神秘代码。输入保证字符串仅包含大小写英文字母,且长度不超过105。

输出描述:
仅一个整数,表示这次滚键盘的过程中,Sumo家的猫摁CAPSLOCK键的最少次数。

示例1
输入
ZUCCAcmLab

输出
3

示例2
输入
MEOWMEOWMEOWGiveMeCatFoodMEOWMEOWMEOW

输出
8

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

char ch[100010];
int main()
{
	cin>>ch;
	int len=strlen(ch), cnt=0;
	for(int i=0;i<len;){
		if(  ( (ch[i]>='A'&&ch[i]<='Z') && (ch[i+1]>='a'&&ch[i+1]<='z') ) ||( (ch[i]>='a'&&ch[i]<='z') && (ch[i+1]>='A'&&ch[i+1]<='Z') ) ) cnt++,i++;
		else i++;
	}
	if(ch[0]>='a'&&ch[0]<='z') cnt++; //一开始可能是小写字母 
	cout<<cnt<<endl;
	return 0;
}

问题B
在这里插入图片描述

输入
2
1
5
10
56 12 1 99 1000 234 33 55 99 812

输出
0.00
291.90

// B.
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10000;
double a[N];
int t,n;

int main()
{
	cin>>t;
	while(t--) {
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		
		sort(a+1,a+1+n);
		double sum=0,res=0;
		
		for(int i=2;i<=n;i++) {
			res+=a[i-1];
			sum+=res;
		}
		printf("%.2lf\n",sum/(n)*1.0);
	}
}

问题F
在这里插入图片描述
输入
2
1
2

输出
1
4

备注:
In the second sample, Sumo has four situations to drive:
Choose cars with numbers 1 and 2, drive the car with number 1,
Choose cars with numbers 1 and 2, drive the car with number 2,
Choose the car with numbers 1, drive the car with number 1,
Choose the car with numbers 2, drive the car with number 2.
So the answer is 4.

// F.
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
typedef long long ll;

int t;
ll n;

ll quick(ll a,ll b)
{
	ll res=1;
	while(b) {
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int main()
{
	cin>>t;
	while(t--){
		cin>>n;
		cout<<n*quick(2,n-1)%MOD<<endl;
	}
}

问题L
在这里插入图片描述
输入
1
2 1 1

输出
ALL

备注:
In the example, Sumo can flip the coin facing up or down so that all the coins are facing the same way after the first operation.

// L.
#include <iostream>
using namespace std;
int t,n,a,b;

void check(int x,int y,int n){
	while(x!=0 && y!=0){
		if(x>y){
			x=n-1-x;
			y=n-x;
		}
		else{
			y=n-1-y;
			x=n-y;
		}
	}
	if(x==0)  cout<<"DOWN"<<endl;
	else  cout<<"UP"<<endl;
	return;
}

int main(){
	cin>>t;
	while(t--){
		cin>>n>>a>>b;
		if(n%2==0)	cout<<"ALL"<<endl;
		else	check(a,b,n);
	}
	return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

米莱虾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值