热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

#个人赛第四场解题总结#

链接:clickhere~~涉及字符串的题比较多,有一道题原先在codeforces做过,【题解】A- AandBandChessTimeLimit:1000MS    

 链接:click here~~,密码:nyist

涉及字符串的题比较多,有一道题原先在codeforces做过,

【题解】


A - A and B and Chess

Time Limit:1000MS    Memory Limit:262144KB    64bit
IO Format:
%I64d & %I64u

SubmitStatus
Practice
CodeForces 519A



Description

A and B are preparing themselves for programming contests.

To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.

For each chess piece we know its weight:


  • the queen‘s weight is 9,
  • the rook‘s weight is 5,
  • the bishop‘s weight is 3,
  • the knight‘s weight is 3,
  • the pawn‘s weight is 1,
  • the king‘s weight isn‘t considered in evaluating position.

The player‘s weight equals to the sum of weights of all his pieces on the board.

As A doesn‘t like counting, he asked you to help him determine which player has the larger position weight.



Input

The input contains eight lines, eight characters each — the board‘s description.

The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.

The white pieces are denoted as follows: the queen is represented is ‘Q‘, the rook — as ‘R‘, the bishop — as‘B‘, the knight
— as ‘N‘, the pawn — as ‘P‘, the king — as ‘K‘.

The black pieces are denoted as ‘q‘, ‘r‘, ‘b‘, ‘n‘, ‘p‘,
k‘, respectively.

An empty square of the board is marked as ‘.‘ (a dot).

It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.



Output

Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight
of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.



Sample Input



Input

...QK...
........
........
........
........
........
........
...rk...


Output

White


Input

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR


Output

Draw


Input

rppppppr
...k....
........
........
........
........
K...Q...
........


Output

Black



Hint

In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.

In the second test sample the weights of the positions of the black and the white pieces are equal to 39.

In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.




【解题思路】

题目所述略长,其实看懂了非常容易理解:

统计大写字母和小写字母的对应的数字值,最后判断关系即可:

代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=10005;
#define mem(a,b) memset(a,b,sizeof(a))
#define Max(a,b) a>b?a:b;
#define Min(a,b) achar mapp[maxn][1005];
int main()
{
int n=0,m=0,i,j;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
scanf("%c",&mapp[i][j]);
}
getchar();
}
for(i=0;i<8;i++)
for(j=0;j<8;j++)
{
if(mapp[i][j]==&#39;Q&#39;) m+=9;
if(mapp[i][j]==&#39;R&#39;) m+=5;
if(mapp[i][j]==&#39;B&#39;) m+=3;
if(mapp[i][j]==&#39;N&#39;) m+=3;
if(mapp[i][j]==&#39;P&#39;) m+=1;
if(mapp[i][j]==&#39;q&#39;) n+=9;
if(mapp[i][j]==&#39;r&#39;) n+=5;
if(mapp[i][j]==&#39;b&#39;) n+=3;
if(mapp[i][j]==&#39;n&#39;) n+=3;
if(mapp[i][j]==&#39;p&#39;) n+=1;
}
if(m==n)
{
puts("Draw");
}
if(m>n) {puts("White");}
if(m}


B - A and B and Compilation Errors

Time Limit:2000MS    Memory Limit:262144KB    64bit
IO Format:
%I64d & %I64u

SubmitStatus
Practice
CodeForces 519B



Description

A and B are preparing themselves for programming contests.

B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.

Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another
one mistake.

However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other
programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.

Can you help B find out exactly what two errors he corrected?



Input

The first line of the input contains integer n (3?≤?n?≤?105)
— the initial number of compilation errors.

The second line contains n space-separated integers a1,?a2,?...,?an (1?≤?ai?≤?109)
— the errors the compiler displayed for the first time.

The third line contains n?-?1 space-separated integers b1,?b2,?...,?bn?-?1 —
the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.

The fourth line contains n?-?2 space-separated integers с1,?с2,?...,?сn?-?2 —
the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.



Output

Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.



Sample Input



Input

5
1 5 8 123 7
123 7 5 1
5 1 7


Output

8
123


Input

6
1 4 3 3 5 7
3 7 5 4 3
4 3 7 5


Output

1
3



Hint

In the first test sample B first corrects the error number 8, then the error number 123.

In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.



【解题思路】:
题目看数据就懂了,只是不知道为什么这么出,首先想到的是求和相减,(或者直接模拟一遍)但是应该不会这么简单,感觉要用容器或者异或,但是实际可能是想难了。
代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=10005;
#define mem(a,b) memset(a,b,sizeof(a))
#define Max(a,b) a>b?a:b;
#define Min(a,b) achar mapp[maxn][1005];
int a[1000000],b[1000000],c[1000000];
int main()
{
mem(a,0),mem(b,0),mem(c,0);
int n,m,i,j,k,l;
scanf("%d",&n);
int a1=0,a2=0,a3=0;
for(i=0; i {
scanf("%d",&a[i]);
a1+=a[i];
}
for(i=0; i {
scanf("%d",&b[i]);
a2+=b[i];
}
for(i=0; i {
scanf("%d",&c[i]);
a3+=c[i];
}
printf("%d\n",a1-a2);
printf("%d\n",a2-a3);
}


C - A and B and Team Training

Time Limit:1000MS    Memory Limit:262144KB    64bit
IO Format:
%I64d & %I64u

SubmitStatus
Practice
CodeForces 519C



Description

A and B are preparing themselves for programming contests.

An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solving
problems together with experienced participants.

A believes that the optimal team of three people should consist of one experienced participant and two newbies. Thus, each experienced participant can share the experience with a large number of people.

However, B believes that the optimal team should have two experienced members plus one newbie. Thus, each newbie can gain more knowledge and experience.

As a result, A and B have decided that all the teams during the training session should belong to one of the two types described above. Furthermore, they agree that the total number of teams should be as much as possible.

There are n experienced members and m newbies on the training session. Can you
calculate what maximum number of teams can be formed?



Input

The first line contains two integers n and m (0?≤?n,?m?≤?5·105)
— the number of experienced participants and newbies that are present at the training session.



Output

Print the maximum number of teams that can be formed.



Sample Input



Input

2 6


Output

2


Input

4 5


Output

3



Hint

Let‘s represent the experienced players as XP and newbies as NB.

In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB).

In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB).




【解题思路】:
题目看懂就明白了:
给出 n 个  experienced participants  和 m 个 newbies ,需要组成尽量多的组,组由3个人组成。有两种组合方式:(1)1 个 experienced participant 和
2 个  newbie  (2)2 个 experienced participant 和 1 个  newbie。问最多能组成的组数是多少组。
(排列组合)
如果大的数不比小的数达到两倍以上的话,即满足

 ps:这样写比较直观

#include
#include
#include
#include
#include
using namespace std;
int main()
{
int n, m;
scanf("%d %d",&n,&m);
if(m>=2*n)
{
cout< }
else if(n>=2*m)
{
cout< }
else{
cout<<(m+n)/3< }
return 0;
}


F - DNA Alignment

Time Limit:2000MS    Memory Limit:262144KB    64bit
IO Format:
%I64d & %I64u

SubmitStatus
Practice
CodeForces 520C



Description

Vasya became interested in bioinformatics. He‘s going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.

Let‘s assume that strings s and t have the same length n,
then the function h(s,?t) is defined as the number of positions in which the
respective symbols of s and t are the
same
. Function h(s,?t) can be used to define the function of Vasya distance ρ(s,?t):

技术分享

where 技术分享 is obtained from string s,
by applying left circular shift i times. For example,
ρ("AGC",?"CGT")?=?

h("AGC",?"CGT")?&#43;?h("AGC",?"GTC")?&#43;?h("AGC",?"TCG")?&#43;?

h("GCA",?"CGT")?&#43;?h("GCA",?"GTC")?&#43;?h("GCA",?"TCG")?&#43;?

h("CAG",?"CGT")?&#43;?h("CAG",?"GTC")?&#43;?h("CAG",?"TCG")?=?

1?&#43;?1?&#43;?0?&#43;?0?&#43;?1?&#43;?1?&#43;?1?&#43;?0?&#43;?1?=?6

Vasya found a string s of length n on the Internet. Now he wants to count how
many strings t there are such that the Vasya distance from the string s attains
maximum possible value. Formally speaking, t must satisfy the equation: 技术分享.

Vasya could not try all possible strings to find an answer, so he needs your help. As the answer may be very large, count the number of such strings modulo 109?&#43;?7.



Input

The first line of the input contains a single integer n (1?≤?n?≤?105).

The second line of the input contains a single string of length n, consisting of characters "ACGT".



Output

Print a single number — the answer modulo 109?&#43;?7.



Sample Input



Input

1
C


Output

1


Input

2
AG


Output

4


Input

3
TTT


Output

1



Hint

Please note that if for two distinct strings t1 and t2 values ρ(s,?t1) и ρ(s,?t2) are
maximum among all possible t, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.

In the first sample, there is ρ("C",?"C")?=?1, for the remaining strings t of
length 1 the value of ρ(s,?t) is 0.

In the second sample, ρ("AG",?"AG")?=?ρ("AG",?"GA")?=?ρ("AG",?"AA")?=?ρ("AG",?"GG")?=?4.

In the third sample, ρ("TTT",?"TTT")?=?27




【解题思路】
之前有印象,


题意:给一个由A,T,C,G组成的字符串s,求使函数ρ(s,t)最大的t的个数。易知,t应该由字符串s中个数最多的字母组成(总数最多的字母只有一个的时候很好理解,如果有多个字母的个数相同,那么就可以将这些个数相同的字母看成一个字母,这样是等价的),求出字母个数最多的种类数x,根据排列组合,答案就是x^n。
代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=100100;
#define mem(a,b) memset(a,b,sizeof(a))
#define LL long long
#define Max(a,b) a>b?a:b;
#define Min(a,b) achar mapp[maxn][1005];
int a[10],b[100000];
const int mod=1e9+7;
int n,m,i,j,A,G,C,T;
char str[maxn];
int main()
{
// while(scanf("%d",&n))
// {
scanf("%d",&n);
getchar();
scanf("%s",str);
int ss=0;
for(int i=0; i {
if(str[i]==&#39;A&#39;) A++;
if(str[i]==&#39;G&#39;) G++;
if(str[i]==&#39;C&#39;) C++;
if(str[i]==&#39;T&#39;) T++;
}
int m1=Max(A,G);
int m2=Max(C,T);
int maxx=Max(m1,m2);
if(A==maxx) ss++;
if(G==maxx) ss++;
if(C==maxx) ss++;
if(T==maxx) ss++;
LL ans=1;
for(int i=0; i {
ans=(ans*ss)%mod;
}
printf("%lld\n",ans%mod);
}E
久违的月赛之一和
I
久违的月赛之二,实在没思路。不知道题目要我们求的是什么,赛后看了解题报告:
 &#20284;乎一知半解:
参考博客: http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246111c3aa6e07b22121980853a3c50f11e41bca770216c5d61aa98cf8a4ad6bc912d3bcd7a742613d20955c418dfdc4653d620e15aeaae12&p=8b2a9700959459b908e2962856&newp=9a7e8614ce904ead17bd9b7c4453d8304a02c70e3f98&user=baidu&fm=sc&query=fzu-&#43;2139&qid=a3324cd5000853b1&p1=1
大家如果有问题,想法,欢迎交流~~


推荐阅读
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文讲述了作者通过点火测试男友的性格和承受能力,以考验婚姻问题。作者故意不安慰男友并再次点火,观察他的反应。这个行为是善意的玩人,旨在了解男友的性格和避免婚姻问题。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
  • 动态规划算法的基本步骤及最长递增子序列问题详解
    本文详细介绍了动态规划算法的基本步骤,包括划分阶段、选择状态、决策和状态转移方程,并以最长递增子序列问题为例进行了详细解析。动态规划算法的有效性依赖于问题本身所具有的最优子结构性质和子问题重叠性质。通过将子问题的解保存在一个表中,在以后尽可能多地利用这些子问题的解,从而提高算法的效率。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
author-avatar
mobiledu2502915233
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有