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;
}