第 45 届国际大学生程序设计竞赛(ICPC)亚洲网上区域赛模拟赛

10 篇文章 0 订阅

A Easy Equation
链接:https://ac.nowcoder.com/acm/contest/8688/A
题目描述
You are given four positive integers 𝑥, 𝑦, 𝑧, 𝑘, please help little M calculate the number of equations 𝑥 + 𝑦 + 𝑧 = 𝑘 when 0 ≤ 𝑥 ≤ 𝑎, 0 ≤ 𝑦 ≤ 𝑏, 0 ≤ 𝑧 ≤ 𝑐, 0 ≤ 𝑘 ≤ 𝑑
输入描述:
Four integers 𝑎, 𝑏, 𝑐, 𝑑 (0 ≤ 𝑎, 𝑏, 𝑐, 𝑑 ≤10^6 )
输出描述:
One integer the number of equations.
It is guaranteed that all the answers fit 64-bit integer.
示例1
输入
3 3 3 3
输出
20
示例2
输入
300 300 300 300
输出
4590551
示例3
输入
0 0 0 0
输出
1
示例4
输入
12345 12345 12345 12345
输出
313713415596

题意
给定 a,b,c,d。求有多少组 x + y + z = d 符合,其中 0 ≤ 𝑥 ≤ 𝑎, 0 ≤ 𝑦 ≤ 𝑏, 0 ≤ 𝑧 ≤ 𝑐, 0 ≤ 𝑘 ≤ 𝑑 。

思路
看到这道题我们先进行一个o(n^3)表的打,我们把这道题变为数列构造求和问题,思路有了,自然能做出。
代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll vis[1000007];
int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;	
	//memset(vis,0,sizeof(vis));
	if(a>b)swap(a,b);
	if(a>c)swap(a,c);
	if(b>c)swap(b,c);
	ll cnt=0;
	ll t=a+b+c;
	ll cc=0,ans=0;
	for(ll i=0;i<=d;i++)
	{
		if(i>t/2)break;
		if(i<=a)
		{
			cnt++;
			cc+=cnt;
		}else if(i<=b)
		{
			cc+=cnt;
		}else if(i<=c&&cnt>=1){
			cnt--;
			cc+=cnt;
		}else {
			if(cnt<2)cnt=0;
			else
			{
				cnt-=2;
				cc+=cnt;
			}		
		}
		vis[i]=cc;
		ans+=cc;
		//cout<<vis[i]<<" "<<cc<<endl;
	}
	if(t%2==0&&d>t/2)
	{
		for(ll i=t/2-1;i>=t/2-(d-t/2);i--)
		{
			ans+=vis[i];
		}
	}else if(t%2==1&&d>t/2)
	{
		for(ll i=t/2;i>=t-d;i--)
		{
			ans+=vis[i];
		}
	}
	printf("%lld\n",ans);
	return 0;
} 

B XTL’s Chessboard
链接:https://ac.nowcoder.com/acm/contest/8688/B

题目描述
Xutianli is a perfectionist, who only owns “Good Chessboard”.

A well-known definition to the Good Chessboard is that there exists two integers u,v which satisfies ux+vy=1+u+v, with the given length x and width y.

Once Zjx came to XTL’s home and brought a small ball. This ball was originally used to hit XTL, because he always touches fish under the pan pond every day(touch fish means dereliction of duty). However, seeing that XTL had really worked conscientiously and enthusiastically, Zjx felt very guilty and gave the ball to XTL as a gift.

After that is a boring time of two boys. XTL design a game based on his “Good Chessboard” Prescribed procedure is as follows.

On the rectangular chessboard composed of squares of X * Y, select a left or bottom grid as the starting grid, and then place a ball in the center of the grid. The diameter of the ball is the length of the side of a grid on the chessboard. Push the ball up 45 degrees to make it roll on the chessboard. When the ball touches the edge of the board, it will bounce back. The rebound rule is: the rebounding route is perpendicular to the original route, just as the reflection of light on a plane mirror. If the ball attaches the corner, it will roll back according to the original route. The ball moves on the chessboard from the starting grid (if the starting grid is in the upper left or lower right corner, it will rebound immediately at the beginning) until it returns to the starting grid.

XTL will take a piece of his cherished chessboard from his storeroom, place the ball, and kick it obliquely up 45 degrees to let Zjx count the number of grids the ball has passed through for odd number of times and tell XTL the answer after the ball stops moving.

Zjx dislikes the game as boring. He wants to do some homework about the Lie Algebroid connection, to discuss some properties about commutative group, to find out some new Mathematical technique in order to improve the effectiveness and robustness of traditional algorithms, and finally send several SCI articles randomly for the sake of postgraduate recommendation.

Smart as you, can you tell him the solution OF this extremely depressing Question?

输入描述:
The input consists of a single test case specified with two lines. The first line contains four integers x, y, a and b, where x is the length of the chessboard, y is the width of chessboard, a,b is the coordinate of the starting grids(x,y>=2,x*y<=1000000000)
输出描述:
The output consists of a single integer, representing the number of grids the ball has passed through for odd number of times.
示例1
输入
13 6 1 5
输出
2
说明
在这里插入图片描述
题意
给定小球原点,小球一开始45度右上出发,不断反弹,回到原点,问有几个格子小球经过奇数次。

思路
根据题意第二段,不可能出现正方形的情况,长方形情况下不管放哪,都是弹到原路返回,所以直接输出2即可。
应该是模拟赛测试数据不严谨,错误代码也过了。

错误代码!!!

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll x,y,a,b;
    cin>>x>>y>>a>>b;
    if((a==x&&b==1)||(a==1&&b==y))
    {
        printf("0\n");
    }else if(a==1&&b==1&&x==y)
    {
        printf("1\n");
    }else{
        if(x==y)
        {
            printf("%lld\n",2*x-2);
        }else{
            printf("2\n");
        }
    }
    return 0;
}

正确代码

print('2')

D Pokemon Ultra Sun
链接:https://ac.nowcoder.com/acm/problem/213446

题目描述
Two pokemons are in a battle.One is our and another is the opposite’s.

Our pokemon is in confusion and the opposite’s pokemon is frozen.

Once per turn , the opposite’s pokemon does nothing and our pokemon gives w damages to the opposite’s pokemon with a probability of P while gives w damages to itself with a probability of 1 − P.

Our pokemon has hp1 health points and the opposite’s pokemon has hp2 health points.

If one pokemon’s health points are zero or below zero, the game is over.

Your task is to calculate the expected number of turn.
输入描述:
The first line is an integer T(T ≤ 8) , the number of test cases.

For each test case, the first line contains three integers hp1, hp2, w(1 ≤ hp1, hp2, w ≤ 3000), representing our pokemon’s health points, the opposite’s health points and damage. The second line contains a real number P(0 < P < 1). which is described above.
输出描述:
For each test case, print the expected number of turn rounding to 6 digits after decimal in one line.
示例1
输入
1
1 1 1
0.5
输出
1.000000

题意
求期望问题,给你攻击力大小,和两个人血量,和攻击其中一个人的概率,求能玩多少轮的期望。

思路
dp期望问题,比赛时dp方程推错了,两个人的概率搞反了,唯一搞了一组不是0.5概率的样例也过了,阴差阳错。

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int t;
int hp1,hp2,w;
double p;
double dp[3005][3005];

int main()
{
	scanf("%d",&t);
	while(t--)
	{
		memset(dp, 0, sizeof(dp));
		scanf("%d%d%d%lf",&hp1,&hp2,&w,&p);
		dp[1][1] = 1;
		for(int i=1;i<=hp1;i++)
			for(int j=1;j<=hp2;j++)
			{
				double temp1,temp2;
				if(i - w < 0) temp1 = 0;
				else temp1 = dp[i - w][j];
				if(j - w < 0) temp2 = 0;
				else temp2 = dp[i][j - w];
				dp[i][j] = (1 - p) * (temp1 + 1.0) + p * (temp2 + 1.0);
				//cout<<i<<"--"<<j<<" = "<<dp[i][j]<<endl;
			}
		printf("%.6lf\n",dp[hp1][hp2]);
	}
	return 0;	
}
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值