【比赛链接】:​http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93429#overview

CodeForces 526C Om Nom and Candies

【题目大意】:输入五个数:C,hr,hb,wr,wb,你最多可以吃C千克的糖, 有两种糖,每种糖有两个参数,一个为重 w  ,一个为欢乐度 h , 如何选择才能拥有最高的欢乐度,  两种糖数量不限。

【思路】贪心,我们假设全部选红色,得到红色糖果最多的数量,然后在考虑在这范围里面退掉j个红色糖果,对选取绿色糖果的影响,然后一样的考虑全部绿色糖果重复前面的操作,最后两个值比较取最大。

代码:

/*  
* Problem: CodeForces 526C
* Running time: 31MS
* Complier: G++
* Author: herongwei
* Create Time: 17:49 2015/10/2 星期五
*/
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

const double pi=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-8;
const int maxn=1e5+10;
typedef long long LL;
LL arr[maxn];
LL c,hr,hb,wr,wb;
char str[10000000];
int main()
{
while(cin>>c>>hr>>hb>>wr>>wb)
{
LL a1=c/wr*hr;
LL a2=c/wb*hb;
LL a3=c/(wr+wb)*(hr+hb);
LL a4=c/wr; // xuan red
LL ans1=-9999999999;
for(int j=0; j<=a4&&j<=maxn; ++j)
{
LL a5=((c-(a4-j)*wr)/wb)*hb;
ans1=max(ans1,(a4-j)*hr+a5);
}
LL ans2=-9999999999;
LL a6=c/wb;
for(int j=0; j<=a6&&j<=maxn; ++j)
{
LL a7=((c-(a6-j)*wb)/wr)*hr;
ans2=max(ans2,(a6-j)*hb+a7);
}
printf("%lld\n",max(ans1,ans2));
}
return 0;
}


Problem D

 CodeForces 526A King of Thieves


【题目大意】:给你一行字符串,判断能否在这个字符串上连续跳跃4次,每次跳的位置必须是‘*’,第一步不一定是第一个‘*’。

【思路】暴力枚举即可

代码:

/*
* Problem: CF CodeForces 526A
* Running time: 0MS
* Complier: G++
* Author: herongwei
* Create Time: 12:27 2015/10/2 星期五
*/

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

const double pi=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-8;
const int maxn=1e5+10;
typedef long long LL;
LL arr[maxn];
LL c,hr,hb,wr,wb;
char str[1000000];
int main()
{
int n;
while(cin>>n)
{
scanf("%s", str);
int ok = 0,okk=0;
int k;
int ck;
for(int i = 0; i < n && !ok; ++i)
{
for(int j = 1; j < n && !ok; ++j)
{
for(k = 0; k < 5; ++k)
{
ck=i+j * k;
if(ck>=n||str[ck]!= '*') break;
}
if(k==5) ok=1;
}
}
if(ok == 1) puts("yes");
else puts("no");
}
return 0;
}


Problem J

CodeForces 519C A and B and Team Training


【题目大意】: 有A和B两组人,现在用A和B里挑3个人合成一组,可以(AAB)或(BBA),问最多可以组多少组。

【思路】 如果A组人较多,则A组出两个,否则B组出两个。

代码:

/*
* Problem: CF CodeForces 519C
* Running time: 0MS
* Complier: G++
* Author: herongwei
* Create Time: 12:27 2015/10/2 星期五
*/

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

const double pi=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-8;
const int maxn=1e5+10;
typedef long long LL;
int main()
{
int n,m,t;
while(scanf("%d%d",&n,&m)==2)
{
if(n<=m/2) t=n;
else if(m<=n/2) t=m;
else t=(m+n)/3;
printf("%d\n",t);
} return 0;
}