Codeforces Round #186 (Div. 2)

A 题水题,如果n<0删除最后一位或倒数第二位的数,找数最大的删除!

#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	int n,ans;
	scanf("%d",&n);
	if(n>=0) printf("%d\n",n);
	else
	{
		n=-n;
		ans=-(n/100*10+min(n%10,n/10%10));
	    printf("%d\n",ans);
	}
	return 0;
}

 

B 题给你一个字符串判断在{L,R) 区间内 si = si + 1.的个数,水水的遍历就好。

 

#include <cstring>
#include <string>
#include <cstdio>
#include <iostream>

using namespace std;

const int maxn =100000 +10;

int ans[maxn],m;

int main()
{
	string s;
	cin>>s;
	ans[0]=0;
	for(int i=1;i<s.length();i++)
	    ans[i]=ans[i-1]+(s[i-1]==s[i]);
	scanf("%d",&m);
	while(m--)
	{
		int l, r; 
		scanf("%d %d",&l,&r);
		printf("%d\n",ans[r-1]-ans[l-1]);
	}
	return 0;
}



 C题  给你4^n个数,让你放进那个2^n * 2^n的矩阵里让这个矩阵beauty值最大,beauty值的计算方法题里说了。。。

The beauty of a 2n × 2n-sized matrix is an integer, obtained by the following algorithm:

  1. Find the maximum element in the matrix. Let's denote it as m.
  2. If n = 0, then the beauty of the matrix equals m. Otherwise, a matrix can be split into 4 non-intersecting 2n - 1 × 2n - 1-sized submatrices, then the beauty of the matrix equals the sum of number m and other four beauties of the described submatrices.

As you can see, the algorithm is recursive.

 

贪心吧,贪心就行,排个序解决了~

 

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

const int maxn = 2000000 + 10 ;

typedef long long LL;

LL a[maxn];

bool cmp(LL a,LL b)
{
	return a>b;
}

int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		LL sum=0;
		for(int i=0;i<n;i++)
		    scanf("%lld",&a[i]);
		sort(a,a+n,cmp);
		while(n)
		{
			for(int i=0;i<n;i++)
			  sum+=a[i];
			n/=4;
		}
		printf("%lld\n",sum);
	}
	return 0;
} 


 


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值