qdu_ACM集训队3月5号组队训练

A Alien’s Organ
There’s an alien whose name is Marjar. It is an universal solder came from planet Highrich a long time ago.

Marjar is a strange alien. It needs to generate new organs(body parts) to fight. The generated organs will provide power to Marjar and then it will disappear. To fight for problem of moral integrity decay on our earth, it will randomly generate new fighting organs all the time, no matter day or night, no matter rain or shine. Averagely, it will generate λ new fighting organs every day.

Marjar’s fighting story is well known to people on earth. So can you help to calculate the possibility of that Marjar generates no more than N organs in one day?

Input
The first line contains a single integer T (0 ≤ T ≤ 10000), indicating there are T cases in total. Then the following T lines each contains one integer N (1 ≤ N ≤ 100) and one float number λ (1 ≤ λ ≤ 100), which are described in problem statement.
Output
For each case, output the possibility described in problem statement, rounded to 3 decimal points.
Sample Input
3
5 8.000
8 5.000
2 4.910
Sample Output
0.191
0.932
0.132
迫松分布,第一次遇见这中题,还特意上网查了查迫松分布啥意思。。
代码如下:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;

int t;
int n;
double f;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%lf",&n,&f);
		double sum=1;
		double ans=0;
		for(int i=0;i<=n;i++)//题目说是不大于n,所以就是从零到n。0的时候0的阶乘就是1。
		{
			if(i==0) 
			{
				ans+=1;
				continue;
			}
			sum*=f;
			sum/=(double) i;
			ans+=sum;
		}
		ans*=exp(-f);//迫松分布函数,紧急
		printf("%.3lf\n",ans);
	}
}

Happy Programming Contest
In Zhejiang University Programming Contest, a team is called “couple team” if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color for each problem they solved. Since the girl would prefer pink balloon rather than black balloon, each color is assigned a value to measure its attractiveness. Usually, the boy is good at programming while the girl is charming. The boy wishes to solve problems as many as possible. However, the girl cares more about the lovely balloons. Of course, the boy’s primary goal is to make the girl happy rather than win a prize in the contest.

Suppose for each problem, the boy already knows how much time he needs to solve it. Please help him make a plan to solve these problems in strategic order so that he can maximize the total attractiveness value of balloons they get before the contest ends. Under this condition, he wants to solve problems as many as possible. If there are many ways to achieve this goal, he needs to minimize the total penalty time. The penalty time of a problem is equal to the submission time of the correct solution. We assume that the boy is so clever that he always submit the correct solution.

Input
The first line of input is an integer N (N < 50) indicating the number of test cases. For each case, first there is a line containing 2 integers T (T <= 1000) and n (n <= 50) indicating the contest length and the number of problems. The next line contains n integers and the i-th integer ti (ti <= 1000) represents the time needed to solve the ith problem. Finally, there is another line containing n integers and the i-th integer vi (vi <= 1000) represents the attractiveness value of the i-th problem. Time is measured in minutes.

Output
For each case, output a single line containing 3 integers in this order: the total attractiveness value, the number of problems solved, the total penalty time. The 3 integers should be separated by a space.

Sample Input
2
300 10
10 10 10 10 10 10 10 10 10 10
1 2 3 4 5 6 7 8 9 10
300 10
301 301 301 301 301 301 301 301 301 301
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000

Sample Output
55 10 550
0 0 0
dp题目,几乎每一次都有dp题。
这个题第一次看的时候,就觉得有点像01背包,但是不知道怎么弄。由于题目说是在总价值最大的时候,出题数最大,罚时最小。一开始是按价值排的序,样例过了,然后wa了。后来按着时间有小到大排序。就过了。后来想了想,就算是不按着价值排序,在dp的时候,也还是会找到时间最大值的,但是那个时间罚时就不一定了。代码如下

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;

const int maxx=1e3+100;
ll dp[4][maxx];
struct node{
	int w;
	int val;
}p[maxx];
int sumt,n;

bool cmp(const node &a,const node &b)
{
	return a.w<b.w;
}

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&sumt,&n);
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++) scanf("%d",&p[i].w);
		for(int i=0;i<n;i++) scanf("%d",&p[i].val);
		sort(p,p+n,cmp);
		for(int i=0;i<n;i++)
		{
			for(int j=sumt;j>=0;j--)
			{
				if(dp[0][j]<dp[0][j-p[i].w]+p[i].val&&j-p[i].w>=0)
				{
					dp[0][j]=dp[0][j-p[i].w]+p[i].val;
					dp[1][j]=dp[1][j-p[i].w]+1;
					dp[2][j]=dp[2][j-p[i].w]+p[i].w;
					dp[3][j]=dp[3][j-p[i].w]+dp[2][j];
				}
			}
		}
		printf("%d %d %d\n",dp[0][sumt],dp[1][sumt],dp[3][sumt]);
	}
	
}

还有两个题是队友做的。代码暂无
努力加油a啊,(o)/~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

starlet_kiss

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

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

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

打赏作者

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

抵扣说明:

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

余额充值