A - Digit Sum 2


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.

Constraints

  • 1≤N≤1016
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.


Sample Input 1

Copy
100

Sample Output 1

Copy
18

For example, the sum of the digits in 99 is 18, which turns out to be the maximum value.


Sample Input 2

Copy
9995

Sample Output 2

Copy
35

For example, the sum of the digits in 9989 is 35, which turns out to be the maximum value.


Sample Input 3

Copy
3141592653589793

Sample Output 3

Copy
137

找小于等于一个数的位数和最大

很容易想到就是尽量多的填9,比如3位数我就可以填首位,其他的填9,所以就是首位-1+9*(位数-1)

但是99的时候我是可以99的啊,这种贪心就会忽略,所以正确的方式是先把这个数+1

公式为9*(位数-1)+(n+1)的首位-1

#include<bits/stdc++.h>
using namespace std;
long long n,s;
int main()
{
cin>>n,n++;
while(n>)s+=,n/=;
cout<<s+n-;
return ;
}

B - Holes


Time limit : 2sec / Memory limit : 256MB

Score : 600 points

Problem Statement

There are N holes in a two-dimensional plane. The coordinates of the i-th hole are (xi,yi).

Let R=10101010. Ringo performs the following operation:

  • Randomly choose a point from the interior of a circle of radius R centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen.

For every i (1≤iN), find the probability that Snuke falls into the i-th hole.

Here, the operation of randomly choosing a point from the interior of a circle of radius R is defined as follows:

  • Pick two real numbers x and y independently according to uniform distribution on [−R,R].
  • If x2+y2≤R2, the point (x,y) is chosen. Otherwise, repeat picking the real numbers x,y until the condition is met.

Constraints

  • 2≤N≤100
  • |xi|,|yi|≤106(1≤iN)
  • All given points are pairwise distinct.
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N
x1 y1
:
xN yN

Output

Print N real numbers. The i-th real number must represent the probability that Snuke falls into the i-th hole.

The output will be judged correct when, for all output values, the absolute or relative error is at most 10−5.


Sample Input 1

Copy
2
0 0
1 1

Sample Output 1

Copy
0.5
0.5

If Ringo put Snuke in the region x+y≤1, Snuke will fall into the first hole. The probability of this happening is very close to 0.5. Otherwise, Snuke will fall into the second hole, the probability of which happening is also very close to 0.5.


Sample Input 2

Copy
5
0 0
2 8
4 5
2 6
3 10

Sample Output 2

Copy
0.43160120892732328768
0.03480224363653196956
0.13880483535586193855
0.00000000000000000000
0.39479171208028279727

这个题就是一个很简单的几何

#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-.);
const int N=;
int n,x[N],y[N];
double p[N+N];
signed main()
{
cin>>n;
for(int i=; i<n; i++)cin>>x[i]>>y[i];
for(int i=; i<n; i++)
{
int tot=;
for(int j=; j<n; j++)
if(i!=j)p[tot++]=atan2(y[j]-y[i],x[j]-x[i]);
sort(p,p+tot);
for(int j=; j<tot; j++)p[j+tot]=p[j]+*pi;
double ans=;
for(int j=; j<tot; j++)ans=max(ans,pi-p[j+tot-]+p[j]);
printf("%.8f\n",ans//pi);
}
return ;
}

C - Tiling


Time limit : 2sec / Memory limit : 256MB

Score : 900 points

Problem Statement

Takahashi has an N×M grid, with N horizontal rows and M vertical columns. Determine if we can place A 1×2 tiles (1 vertical, 2horizontal) and B 2×1 tiles (2 vertical, 1 horizontal) satisfying the following conditions, and construct one arrangement of the tiles if it is possible:

  • All the tiles must be placed on the grid.
  • Tiles must not stick out of the grid, and no two different tiles may intersect.
  • Neither the grid nor the tiles may be rotated.
  • Every tile completely covers exactly two squares.

Constraints

  • 1≤N,M≤1000
  • 0≤A,B≤500000
  • NMA and B are integers.

Input

Input is given from Standard Input in the following format:

N M A B

Output

If it is impossible to place all the tiles, print NO. Otherwise, print the following:

YES
c11…c1M
:
cN1…cNM

Here, cij must be one of the following characters: .<>^ and v. Represent an arrangement by using each of these characters as follows:

  • When cij is ., it indicates that the square at the i-th row and j-th column is empty;
  • When cij is <, it indicates that the square at the i-th row and j-th column is covered by the left half of a 1×2 tile;
  • When cij is >, it indicates that the square at the i-th row and j-th column is covered by the right half of a 1×2 tile;
  • When cij is ^, it indicates that the square at the i-th row and j-th column is covered by the top half of a 2×1 tile;
  • When cij is v, it indicates that the square at the i-th row and j-th column is covered by the bottom half of a 2×1 tile.

Sample Input 1

Copy
3 4 4 2

Sample Output 1

Copy
YES
<><>
^<>^
v<>v

This is one example of a way to place four 1×2 tiles and three 2×1 tiles on a 3×4 grid.


Sample Input 2

Copy
4 5 5 3

Sample Output 2

Copy
YES
<>..^
^.<>v
v<>.^
<><>v

Sample Input 3

Copy
7 9 20 20

Sample Output 3

Copy
NO

C这是要大力模拟?没有想到好做法

抄了一个思路

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int m,n,a,b;
char c[][];
int main()
{
scanf("%d%d%d%d",&m,&n,&a,&b);
for(int i=; i<=m; i++)
for(int j=; j<=n; j++)c[i][j]='.';
if(n&)
{
for(int i=; i<m&&b; i+=)
c[i][n]='^',c[i+][n]='v',b--;
}
if((b&)&&(m&)&&n>&&m>)
c[m-][n-]='^',c[m][n-]='v',b--;
for(int i=; i<m; i++)
for (int j=; j<=n-(n&)&&b; j++)
if(c[i][j]=='.'&&c[i+][j]=='.')
c[i][j]='^',c[i+][j]='v',b--;
for(int i=; i<=m; i++)
for(int j=; j<n&&a; j++)
if(c[i][j]=='.'&&c[i][j+]=='.')
c[i][j]='<',c[i][j+]='>',a--;
if(a||b)
puts("NO");
else
{
puts("YES");
for(int i=; i<=m; i++)printf("%s\n",c[i]+);
}
return ;
}

D - Reversed LCS


Time limit : 2sec / Memory limit : 256MB

Score : 900 points

Problem Statement

Takahashi has decided to give a string to his mother.

The value of a string T is the length of the longest common subsequence of T and T', where T' is the string obtained by reversing T. That is, the value is the longest length of the following two strings that are equal: a subsequence of T (possibly non-contiguous), and a subsequence of T' (possibly non-contiguous).

Takahashi has a string S. He wants to give her mother a string of the highest possible value, so he would like to change at most Kcharacters in S to any other characters in order to obtain a string of the highest possible value. Find the highest possible value achievable.

Constraints

  • 1≤|S|≤300
  • 0≤K≤|S|
  • S consists of lowercase English letters.
  • K is an integer.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the highest possible value achievable.


Sample Input 1

Copy
abcabcabc
1

Sample Output 1

Copy
7

Changing the first character to c results in cbcabcabc. Let this tring be T, then one longest common subsequence of T and T' is cbabcbc, whose length is 7.


Sample Input 2

Copy
atcodergrandcontest
3

Sample Output 2

Copy
15

一个字符串S,你可以改变其中k个字母,使其变为T,T和T的反转串T' 最长公共子串长度

相当于再求回文串,我改变or不改变然后向内向左扩展就可以了,记忆化搜索避免超时

#include<bits/stdc++.h>
using namespace std;
const int N=;
string s;
int dp[][][],K;
int dfs(int l,int r,int x)
{
if(r<l)return ;
if(l==r)return ;
if(dp[l][r][x]!=-)return dp[l][r][x];//记忆化思想,减少搜索次数
int t=max(dfs(l+,r,x),dfs(l,r-,x));//向左或右扩展一个
if(s[l]==s[r])t=max(t,dfs(l+,r-,x)+);//相等,进行扩展
else if(x)t=max(t,dfs(l+,r-,x-)+);//改变一个字符,向内扩展
return dp[l][r][x]=t;
}
int main()
{
cin>>s>>K;
memset(dp,-,sizeof(dp));
cout<<dfs(,s.size()-,K)<<endl;
return ;
}

E - Ball Eat Chameleons


Time limit : 2sec / Memory limit : 256MB

Score : 1200 points

Problem Statement

In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps NSnuke Chameleons in a cage.

A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:

  • A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
  • A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.

Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:

  • Grab either a red ball or a blue ball.
  • Throw that ball into the cage. Then, one of the chameleons eats it.

After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in Kballs. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.

Constraints

  • 1≤N,K≤5×105
  • N and K are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the possible ways Ringo could have thrown in K balls, modulo 998244353.


Sample Input 1

Copy
2 4

Sample Output 1

Copy
7

We will use R to represent a red ball, and B to represent a blue ball. There are seven ways to throw in balls that satisfy the condition: BRRRRBRBRBRRRRBBRRBRRRRB and RRRR.


Sample Input 2

Copy
3 7

Sample Output 2

Copy
57

Sample Input 3

Copy
8 3

Sample Output 3

Copy
0

Sample Input 4

Copy
8 10

Sample Output 4

Copy
46

Sample Input 5

Copy
123456 234567

Sample Output 5

Copy
857617983

给你n,k

AtCoder Grand Contest 021的更多相关文章

  1. AtCoder Grand Contest 021完整题解

    提示:如果公式挂了请多刷新几次,MathJex的公式渲染速度并不是那么理想. 总的来说,还是自己太弱了啊.只做了T1,还WA了两发.今天还有一场CodeForces,晚上0点qwq... 题解还是要好 ...

  2. Atcoder Grand Contest 021 F - Trinity(dp+NTT)

    Atcoder 题面传送门 & 洛谷题面传送门 首先我们考虑设 \(dp_{i,j}\) 表示对于一个 \(i\times j\) 的网格,其每行都至少有一个黑格的合法的三元组 \((A,B, ...

  3. AtCoder Grand Contest 021 D - Reversed LCS

    Description Takahashi has decided to give a string to his mother. The value of a string T is the len ...

  4. AtCoder Grand Contest 021题解

    传送门 \(A\) 咕咕 ll n,res;bool fl; int main(){ scanf("%lld",&n),fl=1; while(n>9)res+=9, ...

  5. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  6. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  7. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  8. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  9. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

随机推荐

  1. Android商城开发系列(四)——butterknife的使用

    在上一篇博客:Android商城开发系列(三)——使用Fragment+RadioButton实现商城底部导航栏实现商城的底部导航栏时,里面用到了butterknife,今天来讲解一下的butterk ...

  2. linux python升级及全局环境变量设置

    1.下载pythonwget https://www.python.org/ftp/python/3.4.5/Python-3.4.5.tgz 或者去官网下载压缩包 2.安装python3依赖yum ...

  3. Windows UEFI 安装策略的一个细节

    在计算机已连接任何带Windows Boot Manager的硬盘的时候,系统自己不会创建EFI分区,而是用之前的

  4. UVA 10382 Watering Grass (区间覆盖,贪心)

    问题可以转化为草坪的边界被完全覆盖.这样一个圆形就换成一条线段. 贪心,从中选尽量少的线段把区间覆盖,按照把线段按左端点排序,记录一个当前已经覆盖区间的位置cur, 从左端点小于等于cur选一个右端点 ...

  5. POJ 4020 NEERC John's inversion 贪心+归并求逆序对

    题意:给你n张卡,每张卡上有蓝色和红色的两种数字,求一种排列使得对应颜色数字之间形成的逆序对总数最小 题解:贪心,先按蓝色排序,数字相同再按红色排,那么蓝色数字的逆序总数为0,考虑交换红色的数字消除逆 ...

  6. Js笔记-第17课

    课 // 作业 //深度拷贝 var obj = { name:'rong', age:'25', card:['visa','alipay'], nam :['1','2','3','4','4'] ...

  7. cocos2d-x之CCCardinalSplineBy

    CCCardinalSplineBy概念 这个类是样条曲线动作,其创建函数CCCardinalSplineBy::create(float duration, cocos2d::CCPointArra ...

  8. CE软件修改器

    下载地址: 链接:https://pan.baidu.com/s/1WQa5epfmLW92xk0XY10pqw 提取码:jt3k 喜欢请点赞

  9. 【思维题 欧拉图】loj#10106. 单词游戏

    巧妙的模型转化 题目描述 来自 ICPC CERC 1999/2000,有改动. 有 NNN 个盘子,每个盘子上写着一个仅由小写字母组成的英文单词.你需要给这些盘子安排一个合适的顺序,使得相邻两个盘子 ...

  10. 02 Django框架基础(APP的创建访问)

    一.创建项目 1.命令:django-admin startproject sitename 2.IDLE环境:本质上都是执行上述命令 常用命令: python manage.py runserver ...