1-24综合场 补题

1-24
打了一场综合场,状态在往下走,感觉很自闭,这张倒数了,无情补题ing;

C - Circle Game

Utkarsh is forced to play yet another one of Ashish’s games. The game progresses turn by turn and as usual, Ashish moves first.

Consider the 2D plane. There is a token which is initially at (0,0). In one move a player must increase either the x coordinate or the y coordinate of the token by exactly k. In doing so, the player must ensure that the token stays within a (Euclidean) distance d from (0,0).

In other words, if after a move the coordinates of the token are (p,q), then p2+q2≤d2 must hold.

The game ends when a player is unable to make a move. It can be shown that the game will end in a finite number of moves. If both players play optimally, determine who will win.

Input
The first line contains a single integer t (1≤t≤100) — the number of test cases.
The only line of each test case contains two space separated integers d (1≤d≤105) and k (1≤k≤d).

Output
For each test case, if Ashish wins the game, print “Ashish”, otherwise print “Utkarsh” (without the quotes).

Input
5
2 1
5 2
10 3
25 4
15441 33

Output
Utkarsh
Ashish
Utkarsh
Utkarsh
Ashish

这里可以看出(x,y),xy时一定为U(即对角线一定是U),如果取最大的x,(x,y)没有后继状态的话一定U胜,不管A怎么走,U总能总到(x,y)xy。所以U胜。
如果(x,y),x==y且(x,y)有后继状态。那么A先到(1,2),然后无论U怎么走,A都能直接到挨着对称轴U的一条全为A的线上的点(即(x,x+1)),所以A胜。

这就是一道简单的cf想法加博弈题,博弈方面还是不怎么熟啊

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll mod=1000000007;
char s[1000];
int main()
{
	ll t,n,a,b,c,d,e;
	scanf("%lld",&t);
	while(t--)
	{
		ll i=1;
		scanf("%lld%lld",&a,&b);
		while(2*i*i*b*b<=a*a)
		{
			i++;
		}
		i--;
		c=(i+1)*(i+1)*b*b+i*i*b*b;
		if(c<=a*a)
		{
			printf("Ashish\n");
		}else printf("Utkarsh\n");
	}
	return 0;
} 

E - Lavaspar

Word Search is a well-known hobby, although it is losing some of its prestige in recent years. The goal in this game is to find words in an array, where each cell in this matrix contains a letter.

Bibika and her brother were playing Word Search, but soon they lost interest in the game, as finding all the words was getting relatively easy. Bibika would like to take her brother away from the computer, she searched the internet for games of the same style and ended up finding the Lavaspar Hunting.

Lavaspar Hunting is a game that follows the same idea of the famous Word Search. However, instead of simply having to find a word in the matrix, the goal is to find any anagram of the word, making the game more difficult and interesting. The anagram can be found in a row, column or diagonal.

An anagram is a word formed by rearranging the letters of another. Sometimes, an anagram does not exist as a word in the language, but this does not matter. balo, loba and aolb are examples of anagrams of the word bola.

Bibika realized that it was possible for the same cell in the matrix to make part of anagrams of different words and then she started to call these special cells.

Now she would like to know, given an array configuration and a collection of words, how many special cells are there?
在这里插入图片描述
The picture above illustrates the first example, where the collection of words consists of three words: bola, casa and boi. The rectangles of each color represent anagrams of different words from the entry. The 3 special cells are painted yellow.
Input
The first line contains two integers, L and C, which correspond to the number of lines and columns of the array, respectively.
Each one of the next L lines contains a word with C letters.
These lines are followed by a line containing an integer, N, which is the number of words in the collection of words to follow.
Finally, there are now N lines, each of which contains a word in the collection.
All characters in the array and in each word of the collection of words is a capital letter of the English alphabet.
No two of the N words in the collection are anagrams of each other.
2≤L,C≤40.
2≤N≤20.
The number P of letters of each of the N words is in the interval 2≤P≤min(15,max(L,C)).
Output
The output consists of a single line that contains an integer corresponding to the number of special cells.

Input

3 3
AAB
ABA
BAA
2
ABA
BBB

Output

3

前几天刚学的hash就用上了,GOOD;
可惜还是太年轻了,Hash的值不够分散,尽量不要Hash值为0并且增加幂次;

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll maze[45][45];
int vis[45][45];
int vi[45][45];
char ss[40];
ll l,c,n,i,j,p,r,v;
int len;
char x;
void bfs()
{
	ll sum;
	for(int i=1;i<=l;i++)
	{
		for(int j=1;j<=r;j++)
		{
			sum=0;
			if(j+len-1<=r)
			{
				for(int k=0;k<len;k++)
					sum=(sum+maze[i][j+k]);
				if(sum==v)
				{
					for(int k=0;k<len;k++)vis[i][j+k]=1;
				}
			}
			sum=0;
			if(i+len-1<=l)
			{
				for(int k=0;k<len;k++)
					sum=(sum+maze[i+k][j]);
				if(sum==v)
				{
					for(int k=0;k<len;k++)vis[i+k][j]=1;
				}
			}
			sum=0;
			if(i+len-1<=l&&j+len-1<=r)
			{
				for(int k=0;k<len;k++)
					sum=(sum+maze[i+k][j+k]);
				if(sum==v)
				{
					for(int k=0;k<len;k++)vis[i+k][j+k]=1;
				}		
			}
			sum=0;
			if(i+len-1<=l&&j-len+1>0)
			{
				for(int k=0;k<len;k++)
					sum=(sum+maze[i+k][j-k]);
				if(sum==v)
				{
					for(int k=0;k<len;k++)vis[i+k][j-k]=1;
				}	
			} 		
		}
	} 
	for(int i=1;i<=l;i++)
	{
		for(int j=1;j<=r;j++)
		{
			if(vis[i][j])vi[i][j]++;
		}
	}
}
int main()
{
	
	scanf("%lld%lld",&l,&r);
	getchar();
	for(int i=1;i<=l;i++)
	{
		for(int j=1;j<=r;j++)
		{
			vis[i][j]=0;
			vi[i][j]=0;
			scanf("%c",&x);
			maze[i][j]=(x-'A'+1)*(x-'A'+1)*(x-'A'+1)*(x-'A'+1)*(x-'A'+1)*(x-'A'+1);
		}
		getchar();
	}
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		v=0;
		scanf("%s",ss);
		len=strlen(ss);
		for(int k=0;k<len;k++)
		{
			p=(ss[k]-'A'+1)*(ss[k]-'A'+1)*(ss[k]-'A'+1)*(ss[k]-'A'+1)*(ss[k]-'A'+1)*(ss[k]-'A'+1);
			v=(v+p);
		}
		bfs();
		memset(vis,0,sizeof(vis));
	}
	ll num=0;
	for(int i=1;i<=l;i++)
		for(int j=1;j<=r;j++)
			if(vi[i][j]>1)num++;
	printf("%lld\n",num);
	return 0;
} 

H - Sticker Album

The Sticker Album of the ICPC 2020 Nlogonian Subregional just came out! Competitive programming hooligans all over the country are buying albums and collecting stickers, to celebrate the competition.

This sticker album is special because all stickers are equal: a picture of this year’s trophy. To complete the album, you just need to collect enough stickers to fill all the slots in it.

You may be asking yourself: where is the fun in collecting those stickers? Well, to make things interesting, the stickers are sold in packets, each with a random number of stickers! Fans celebrate when they find a high number of stickers in a packet, make fun of those who got unlucky and found low numbers of stickers, and brag about filling their whole albums with just a few packets.

You just acquired your own album, and want to start filling it! But before buying your first sticker packets, you wondered: on average, how many packets does one need to buy in order to fill an album?

Input

The only input line contains three integers N, A and B, separated by a single space, satisfying 1≤N≤106, 0≤A≤B≤106 and B>0, where:

N is the number of stickers it takes to fill an album;
A is the minimum number of stickers in a packet;
B is the maximum number of stickers in a packet.
The number of stickers in each packet is uniformly distributed in the closed interval [A,B].
Output
The output consists of a single line, which must contain the expected number of packets it takes to complete an album. The number will be considered correct if it is within an absolute or relative error of 10−5 of the correct answer.
Input

40 0 2

Output

40.33333

概率DP

第一次遇到概率DP的题目,DP这一块还是要去补a;

这里在a=0时需要特判,然后可以维护一段sum代表从后继状态往前推,这里是用后缀和来实现的;

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll mod=998244353;
double pre[1000005],dp[1000005];
int main()
{
	int n,a,b,i,j;
	scanf("%d%d%d",&n,&a,&b);
	dp[n]=0.0;pre[n]=0.0;
	if(a!=0)
	{
		for(i=n-1;i>=0;i--)
		{
			dp[i]=(1.0/(b-a+1))*(pre[min(n,i+a)]-pre[min(n,i+b+1)])+1;
			pre[i]=pre[i+1]+dp[i];	
		} 
	}else {
		for(i=n-1;i>=0;i--)
		{
			dp[i]=(1.0/b-a)*(pre[min(n,i+1)]-pre[min(n,i+b+1)])+1.0*(b-a+1)/(b-a);
			pre[i]=pre[i+1]+dp[i];	
		}
	}
	printf("%.5lf\n",dp[0]);
	
	return 0;
} 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值