暑期大欢乐(20190811)

这次的欢乐赛,C,G题数据有点水总的来说还是很考思维的!

A-AK的距离

时间限制 : - MS 空间限制 : - KB
评测说明 : 1s,128m

问题描述

同学们总想AK。
于是何老板给出一个由大写字母构成的字符串,他想你帮忙找出其中距离最远的一对'A'和'K'。
比如下列字符串:
BKABGKWAXKA
距离最远一对'A'和'K'的间距为6,它们之间间隔了6个字符。

输入格式

一行,一个由大写字母构成的字符串

输出格式

一个整数,表示A和K最远的间距。要求A必须在K的左侧,如果不存在,输出-1

样例输入 1

BKABGKWAXKA

样例输出 1

6

样例输入 2

KKKKKKKKKKAAAAAAAAAAAAAAA

样例输出 2

-1

提示

1<=字符串的长度<=10000

签到题,从前找出第一个A,从后找出第一个K,保证A在K左侧的话输出长度,否则-1


B-方块消消乐

时间限制 : - MS 空间限制 : - KB
评测说明 : 1s,128m

问题描述

何老板在玩一款消消乐游戏,游戏虽然简单,何老板仍旧乐此不疲。
游戏一开始有n个边长为1的方块叠成一个高为n的柱子。
有红色和蓝色两种方块。
游戏操作:玩家选择两个相邻且不同色的方块,将它们消除。然后上方的方块会自动落下来,使得剩下的方块始终保持柱状。

玩家可以进行任意次上述操作,消除的方块越多,得分越高。何老板想知道:最多能消除掉多少方块?

输入格式

一个由0和1构成的字符串,表示游戏开始时的方块柱子。其中0表示蓝色方块,1表示红色方块。

输出格式

一个整数,表示最多能消除的方块数。

样例输入 1

0011

样例输出 1

4

样例输入 2

11011010001011

样例输出 2

12

样例输入 3

0

样例输出 3

0

提示

设字符串的长度为n
1 1 1 n n n 1 0 5 10^5 105


观察样例发现能删除的方块数等于1 or 0 中的最小的数量×2
m i n min min{ c n t 1 , c n t 0 cnt1,cnt0 cnt1,cnt0 2 2 2


C-怪兽游戏

时间限制 : - MS 空间限制 : - KB
评测说明 : 1s,256m

问题描述

何老板在玩一款怪兽游戏。游戏虽然简单,何老板仍旧乐此不疲。
游戏一开始有N只怪兽,编号1到N。其中第i只怪兽的生命值为  ,如果一只怪兽的生命值>0,那么它还活着。

游戏中,玩家可以反复进行下列操作: 任选一只活着的怪兽X,操控它去攻击任意一只活着的怪兽Y,被攻击的怪兽Y损失的生命值为攻击者X的当前的生命值。

当还剩一只活着的怪兽时,游戏结束。剩余那只怪兽的生命值越小,玩家在此局游戏的得分就越高。
何老板想知道,最后活着那只怪兽的生命值,最小可能是多少,请你帮他算一算。

输入格式

第一行,一个整数N
第二行,N个空格间隔的整数 

输出格式

一个整数,表示能够存活的怪兽的最小生命值

样例输入 1

4
2 10 8 40

样例输出 1

2

样例输入 2

4
5 13 8 1000000000

样例输出 2

1

样例输入 3

3
1000000000 1000000000 1000000000

样例输出 3

1000000000

提示
2 2 2 N N N 1 0 5 10^5 105
1 1 1 A i A_i Ai 1 0 9 10^9 109


做法一(暴力)

首先我们可以观察样例,然后发现了一个暴力做法:
每次取出序列中最小的一个,然后其他数跟它求余,知道有n-1个0为止,剩下的那个数就是答案!

做法二(正解)

求n个数的最大公约数,即是答案


code:

A

#include<bits/stdc++.h> 
using namespace std; 
char s[10005]; 
int main(){ 
    int n,a=0,k=0; 
    cin>>s; 
    n=strlen(s); 
    for(int i=0;i<n;i++){ 
        if(s[i]=='A'){ 
            a=i; 
            break; 
        } 
    } 
    for(int i=n-1;i>=0;i--){ 
        if(s[i]=='K'){ 
            k=i; 
            break; 
        } 
    } 
    if(k-a<1)
    	printf("-1"); 
    else
    	printf("%d",k-a-1); 
    return 0;
}

B

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char a[N];
int cnt1,cnt2;
int main(){
	cin>>a;
	int len=strlen(a)-1;
	for(int i=0;i<=len;i++){
		if(a[i]=='1')
			cnt1++;
		if(a[i]=='0')
			cnt2++;
	}
	printf("%d",min(cnt1,cnt2)*2);
	return 0;
}

C

暴力
#include<bits/stdc++.h> 
using namespace std; 
long long a[100005]; 
int main(){ 
    int n; 
    scanf("%d",&n); 
    for(int i=1;i<=n;i++){ 
        scanf("%lld",&a[i]); 
    } 
    while(true){ 
        int minn=1e9+9,s;
        for(int i=1;i<=n;i++){
            if(a[i]!=0)
                if(a[i]<minn){
                    minn=a[i];
                    s=i;
                }
        }
        long long k=minn,x=0; 
        for(int j=1;j<=n;j++){ 
            if(j==s)
                continue;
            if(a[j]==0)
                x++;
            if(a[j]==0)
                continue;
            a[j]%=k;
        } 
        if(x==n-1){
        	cout<<k;
        	return 0;
        }
        //cout<<x<<endl;
    }
    return 0;
}
正解
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,a[N];
int gcd(int x,int y){
	if(x%y)
		return gcd(y,x%y);
	return y;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(i>1)
			a[i]=gcd(a[i],a[i-1]);
	}
	printf("%d",a[n]);
	return 0;
}

D

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x;
int main(){
	cin>>x;
	double xx=x;
	double ans=(xx/5.5);
	ll Ans=ans;
	if(x-(x/11*11)-6==0){
		cout<<Ans;
		return 0;
	}
	if(Ans*5.5>=x)
		cout<<Ans;
	else
		cout<<Ans+1;
	return 0;
}

E

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000005;
struct node{int x,y;};
bool cmp(node x,node y){
	if(x.y!=y.y)
		return x.y>y.y;
	return x.x<y.x;
}
node a[N];
ll ans;
int n;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d %d",&a[i].x,&a[i].y);
        a[i].x/=2;
        a[i].y/=2;
	}
    sort(a+1,a+n+1,cmp);
    int tmp=0;
    for(int i=1;i<=n;i++){
        if(a[i].x<tmp)
			continue;
        ans+=(ll)(a[i].x-tmp)*a[i].y;
        tmp=a[i].x;
    }
    ans*=4;
    printf("%lld\n",ans);
    return 0;
}

F

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
const int N=10005;
const int inf=1e8;
int k,n,m;
int Last[N],End[N],Next[N],len[N],cost[N],tot;
int dis[105][1005],vis[105];
void cb(int x,int y,int z,int w){
	End[++tot]=y;
	Next[tot]=Last[x];
	Last[x]=tot;
	len[tot]=z;
	cost[tot]=w;
}
queue<int> q;
void spfa(int s){
	q.push(s);
	vis[s]=true;
	for(int i=2;i<=n;i++)
		for(int j=0;j<=k;j++)
			dis[i][j]=inf;
	while(q.size()){
		int x=q.front();
		q.pop();
		vis[x]=false;
		for(int i=Last[x];i;i=Next[i]){
			int y=End[i];
			for(int j=0;j<=k;j++){
				if(dis[x][j]+len[i]<dis[y][j+cost[i]]){
					dis[y][j+cost[i]]=dis[x][j]+len[i];
					if(vis[y]==false){
						vis[y]=true;
						q.push(y);
					}
				}
			}
		}
	}
}
int main(){
	scanf("%d %d %d",&k,&n,&m);
	for(int i=1;i<=m;i++){
		int x,y,z,w;
		scanf("%d %d %d %d",&x,&y,&z,&w);
		cb(x,y,z,w);
	}
	spfa(1);
	printf("%d",dis[n][k]);
	return 0;
}

G

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int n,d,a[30005],ans,maxn,f[30005][505];
int dfs(int x,int len){
	if(x>maxn)
		return 0;
	if(f[x][len]!=-1)//已经讨论过了
		return f[x][len];
	if(len>1)
		f[x][len]=max(f[x][len],dfs(x+len-1,len-1));
	f[x][len]=max(f[x][len],dfs(x+len,len));
	f[x][len]=max(f[x][len],dfs(x+len+1,len+1));
	f[x][len]+=a[x];
	ans=max(ans,f[x][len]);
	return f[x][len];
}
int main(){
	memset(f,-1,sizeof(f));
	scanf("%d %d",&n,&d);
	for(int i=1;i<=n;i++){
		int id;
		scanf("%d",&id);
		a[id]++;
		maxn=max(id,maxn);
	}
	dfs(d,d);
	printf("%d",ans);
	return 0;
}

H

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int n,m,cntx,cnty;
long long ans;
struct node{
	int x,id;
}a[20005];
bool cmp(node x,node y){
	return x.x>y.x;
}
int main(){
	scanf("%d %d",&n,&m);
	n--,m--;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].x);
		a[i].id=0;
	}
	for(int i=n+1;i<=m+n;i++){
		scanf("%d",&a[i].x);
		a[i].id=1;
	}
	sort(a+1,a+1+n+m,cmp);
	for(int i=1;i<=n+m;i++){
		if(a[i].id==0){
			cntx++;
			ans+=(cnty+1)*a[i].x;
		}
		else{
			cnty++;
			ans+=(cntx+1)*a[i].x;
		}
	}
	printf("%lld",ans);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值