A.codeforces1038A

You are given a string ss of length nn, which consists only of the first kk letters of the Latin alphabet. All letters in string ss are uppercase.

A subsequence of string ss is a string that can be derived from ss by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD" are subsequences of "ABCDE", but "DEA" is not.

A subsequence of ss called good if the number of occurences of each of the first kkletters of the alphabet is the same.

Find the length of the longest good subsequence of ss.

Input

The first line of the input contains integers nn (1≤n≤1051≤n≤105) and kk (1≤k≤261≤k≤26).

The second line of the input contains the string ss of length nn. String ss only contains uppercase letters from 'A' to the kk-th letter of Latin alphabet.

Output

Print the only integer — the length of the longest good subsequence of string ss.

Examples

Input
9 3
ACAABCCAB
Output
6
Input
9 4
ABCABCABC
Output
0

Note

In the first example, "ACBCAB" ("ACAABCCAB") is one of the subsequences that has the same frequency of 'A', 'B' and 'C'. Subsequence "CAB" also has the same frequency of these letters, but doesn't have the maximum possible length.

In the second example, none of the subsequences can have 'D', hence the answer is 00.

题意:给你一个字符串s长度为n,让你求的字符串只包含k种字符且出现次数相等,你可以对字符串s进行删减操作,输出求得的字符串的长度
分析:只要找到字符串s里出现次数最少的字符,将它的出现次数乘以k,还要考虑当s里字符种数小于K的情况
 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int n,k,a[],b[];
char s[];
while(~scanf("%d %d",&n,&k))
{
memset(a,,sizeof(a));//a数组用来统计字符种数,如果出现了,就赋为1
memset(b,,sizeof(b));//b数组用来统计每个字符出现的次数
scanf("%s",s);
int kk=;
for(int i=;i<n;i++)
{
if(a[s[i]-'A']==)
{
kk++;//kk就表示s里字符的种数
a[s[i]-'A']=;
}
b[s[i]-'A']++;
}
sort(b,b+k);//排序,找到出现次数最小的字符
if(kk!=k)
printf("0\n");//如果kk不等于给出的k时,输出0
else
printf("%d\n",b[]*k);//最小的出现次数乘以字符种类数 }
return ;
}

B.codeforces1038B

Find out if it is possible to partition the first nn positive integers into two non-empty disjoint sets S1S1 and S2S2 such that:

gcd(sum(S1),sum(S2))>1gcd(sum(S1),sum(S2))>1

Here sum(S)sum(S) denotes the sum of all elements present in set SS and gcdgcd means thegreatest common divisor.

Every integer number from 11 to nn should be present in exactly one of S1S1 or S2S2.

Input

The only line of the input contains a single integer nn (1≤n≤450001≤n≤45000)

Output

If such partition doesn't exist, print "No" (quotes for clarity).

Otherwise, print "Yes" (quotes for clarity), followed by two lines, describing S1S1and S2S2 respectively.

Each set description starts with the set size, followed by the elements of the set in any order. Each set must be non-empty.

If there are multiple possible partitions — print any of them.

Examples

Input
1
Output
No
Input
3
Output
Yes
1 2
2 1 3

Note

In the first example, there is no way to partition a single number into two non-empty sets, hence the answer is "No".

In the second example, the sums of the sets are 22 and 44 respectively. The gcd(2,4)=2>1gcd(2,4)=2>1, hence that is one of the possible answers.

错了两发很是心痛,No,NO,Yes,YES其实很不一样

这题挺简单的,实际上就是构造。

题意:给你一个n,让你把1 to n的所有数分成两组,使得这两组的和的最大公因数不等于1,输出这两组数

分析:当n=1或者n=2时输出No,

当n大于2时,如果n为奇数,第一组数为中间那个数,第二组数为除开中间数的所有数,因为最中间数的旁边两个数之和一定是它的两倍,依次取左边一个右边一个,都满足,所以除开中间那个数的所有数之和一定是中间那个数的倍数。

如果n为偶数,第一组数取第一个数和最后一个数,第二组取剩下的数,因为第一个数与最后一个数之和等于第二个数与倒数第二个数之和,也等于第三个数和倒数第三个数之和....,所以剩下的数之和一定是第一个数和最后一个数之和的倍数。

 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
if(n==||n==)
printf("No\n");//当n=1或n=2
else
{
printf("Yes\n");
if(n%==)//当n时偶数
{
printf("2 1 %d\n",n);//输出第一个数和最后一个数
printf("%d ",n-);//剩下有n-2个数
for(int i=;i<=n-;i++)
{
if(i==n-)
printf("%d\n",i);
else
printf("%d ",i);
}
}
else//当n是奇数
{
printf("1 %d\n",n/+);
printf("%d",n-);//剩下有n-1个数
for(int i=;i<=n;i++)
{
if(i!=n/+)//除开最中间的那个数不输出
printf(" %d",i);
}
printf("\n");
}
}
}
return ;
}

C.1038C Gambling

C. Gambling
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Two players A and B have a list of nn integers each. They both want to maximize the subtraction between their score and their opponent's score.

In one turn, a player can either add to his score any element from his list (assuming his list is not empty), the element is removed from the list afterward. Or remove an element from his opponent's list (assuming his opponent's list is not empty).

Note, that in case there are equal elements in the list only one of them will be affected in the operations above. For example, if there are elements {1,2,2,3}{1,2,2,3} in a list and you decided to choose 22 for the next turn, only a single instance of 22 will be deleted (and added to the score, if necessary).

The player A starts the game and the game stops when both lists are empty. Find the difference between A's score and B's score at the end of the game, if both of the players are playing optimally.

Optimal play between two players means that both players choose the best possible strategy to achieve the best possible outcome for themselves. In this problem, it means that each player, each time makes a move, which maximizes the final difference between his score and his opponent's score, knowing that the opponent is doing the same.

Input

The first line of input contains an integer nn (1≤n≤1000001≤n≤100000) — the sizes of the list.

The second line contains nn integers aiai (1≤ai≤1061≤ai≤106), describing the list of the player A, who starts the game.

The third line contains nn integers bibi (1≤bi≤1061≤bi≤106), describing the list of the player B.

Output

Output the difference between A's score and B's score (A−BA−B) if both of them are playing optimally.

Examples
input

Copy
2
1 4
5 1
output

Copy
0
input

Copy
3
100 100 100
100 100 100
output

Copy
0
input

Copy
2
2 1
5 6
output

Copy
-3
Note

In the first example, the game could have gone as follows:

  • A removes 55 from B's list.
  • B removes 44 from A's list.
  • A takes his 11.
  • B takes his 11.

Hence, A's score is 11, B's score is 11 and difference is 00.

There is also another optimal way of playing:

  • A removes 55 from B's list.
  • B removes 44 from A's list.
  • A removes 11 from B's list.
  • B removes 11 from A's list.

The difference in the scores is still 00.

In the second example, irrespective of the moves the players make, they will end up with the same number of numbers added to their score, so the difference will be 00.

大致题意:有两个人a,b,有两个数组,每个人可以从自己的数组选一个数当作自己的积分,这个数被除去,或者从别人的数组里除去一个数,双方都会进行这个操作,当双方数组里的没有数字的时候,游戏结束,尽可能使得自己的积分最多,最后输出两个人最终积分的差

分析:先给两个数组从小到大排个序,使用双指针,另i=n,j=n;

如果a[i]>b[j]时,

如果轮到a来选,那么a的积分ans1+=a[i],i--;

如果轮到b来选,那么b将a[i]从数组a里除去,i--;

如果a[i]<b[j]时,

如果轮到a来选,那么a将b[j]从数组b里除去,j--;

如果轮到b来选,那么b的积分ans2+=b[j],j--;

如果a[i]=b[j],

跳过i,j,i--,j--

 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int n,a[],b[];
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++)
scanf("%d",&b[i]);
sort(a+,a++n);
sort(b+,b++n);
a[]=;
b[]=;
long long k=,ans1=,ans2=;
for(int i=n,j=n;i>=&&j>=;)
{
if(a[i]>b[j])
{
if(k==)//使用k来标记这轮轮到谁,0是a,1是b
{
ans1+=a[i];
k=;
i--;
}
else
{
i--;
k=;
}
}
else if(a[i]<b[j])
{
if(k==)
{
ans2+=b[j];
k=;
j--;
}
else
{
k=;
j--;
}
}
else if(a[i]==b[j])
{
i--;
j--;
}
}
printf("%lld\n",ans1-ans2);
}
return ;
}

D.codeforces1040a

A group of nn dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing moves and can't change positions. For some of them, a white dancing suit is already bought, for some of them — a black one, and for the rest the suit will be bought in the future.

On the day when the suits were to be bought, the director was told that the participants of the olympiad will be happy if the colors of the suits on the scene will form a palindrome. A palindrome is a sequence that is the same when read from left to right and when read from right to left. The director liked the idea, and she wants to buy suits so that the color of the leftmost dancer's suit is the same as the color of the rightmost dancer's suit, the 2nd left is the same as 2nd right, and so on.

The director knows how many burls it costs to buy a white suit, and how many burls to buy a black suit. You need to find out whether it is possible to buy suits to form a palindrome, and if it's possible, what's the minimal cost of doing so. Remember that dancers can not change positions, and due to bureaucratic reasons it is not allowed to buy new suits for the dancers who already have suits, even if it reduces the overall spending.

Input

The first line contains three integers nn, aa, and bb (1≤n≤201≤n≤20, 1≤a,b≤1001≤a,b≤100) — the number of dancers, the cost of a white suit, and the cost of a black suit.

The next line contains nn numbers cici, ii-th of which denotes the color of the suit of the ii-th dancer. Number 00 denotes the white color, 11 — the black color, and 22denotes that a suit for this dancer is still to be bought.

Output

If it is not possible to form a palindrome without swapping dancers and buying new suits for those who have one, then output -1. Otherwise, output the minimal price to get the desired visual effect.

Examples

Input
5 100 1
0 1 2 1 2
Output
101
Input
3 10 12
1 2 0
Output
-1
Input
3 12 1
0 1 0
Output
0

Note

In the first sample, the cheapest way to obtain palindromic colors is to buy a black suit for the third from left dancer and a white suit for the rightmost dancer.

In the second sample, the leftmost dancer's suit already differs from the rightmost dancer's suit so there is no way to obtain the desired coloring.

In the third sample, all suits are already bought and their colors form a palindrome.

题意:有n个舞者,白色衣服的价格是a,黑色衣服的价格是b,第二行有n个数字,0表穿白衣服的,1表示穿黑衣服的, 2表示还没买服装的,要使得该n个数字形成一个回文串,且花的钱最少。

 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int n,a,b,c[];
while(~scanf("%d %d %d",&n,&a,&b))
{
for(int i=;i<=n;i++)
scanf("%d",&c[i]);
int t,tt,ans=,i;
tt=min(a,b);//tt表示黑白服装里便宜的那个
if(n%==)
t=n/;
else
t=n/+;//当n是奇数的时候,中间那个数是n/2+1.
for( i=;i<=t;i++)
{
if(c[i]!=c[n-i+])//当服装颜色不等于与他对称的人的颜色
{
if((c[i]==&&c[n-i+]==)||(c[i]==&&c[n-i+]==))
{
break;//如果是0,1,1,0不可能形成回文
}
else if(c[i]==)//如果他没有服装
{
if(c[n-i+]==)//与他对称的人服装是黑色
ans+=b;
else if(c[n-i+]==)//与他对称的人的服装是白色
ans+=a;
}
else if(c[i]==&&c[n-i+]==)//如果他的服装是白色,与他对称的人没有服装
ans+=a;
else if(c[i]==&&c[n-i+]==)//如果他的服装是黑色,与他对称的人没有服装
ans+=b;
}
else//如果服装颜色相同
{
if(c[i]==&&c[n-i+]==)//如果他俩都没有服装
ans+=*tt;
if(i==t&&t==n/+&&c[i]==)//如果是奇数的时候,到中间的时候,就多加了一个人的服装,要减去
ans-=tt;
}
}
if(i==t+)
printf("%d\n",ans);
else
printf("-1\n");
}
return ;
}

E - E(模拟)

CodeForces - 1040B Shashlik Cooking

time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simultaneously. There are two states for each skewer: initial and turned over.

This time Miroslav laid out nn skewers parallel to each other, and enumerated them with consecutive integers from 11 to nn in order from left to right. For better cooking, he puts them quite close to each other, so when he turns skewer number ii, it leads to turning kk closest skewers from each side of the skewer ii, that is, skewers number i−ki−k, i−k+1i−k+1, ..., i−1i−1, i+1i+1, ..., i+k−1i+k−1, i+ki+k (if they exist).

For example, let n=6n=6 and k=1k=1. When Miroslav turns skewer number 33, then skewers with numbers 22, 33, and 44 will come up turned over. If after that he turns skewer number 11, then skewers number 11, 33, and 44 will be turned over, while skewer number 22 will be in the initial position (because it is turned again).

As we said before, the art of cooking requires perfect timing, so Miroslav wants to turn over all nn skewers with the minimal possible number of actions. For example, for the above example n=6n=6 and k=1k=1, two turnings are sufficient: he can turn over skewers number 22 and 55.

Help Miroslav turn over all nn skewers.

Input

The first line contains two integers nn and kk (1≤n≤10001≤n≤1000, 0≤k≤10000≤k≤1000) — the number of skewers and the number of skewers from each side that are turned in one step.

Output

The first line should contain integer ll — the minimum number of actions needed by Miroslav to turn over all nn skewers. After than print llintegers from 11 to nn denoting the number of the skewer that is to be turned over at the corresponding step.

Examples
input

Copy
7 2
output

Copy
2
1 6
input

Copy
5 1
output

Copy
2
1 4
Note

In the first example the first operation turns over skewers 11, 22 and 33, the second operation turns over skewers 44, 55, 66 and 77.

In the second example it is also correct to turn over skewers 22 and 55, but turning skewers 22 and 44, or 11 and 55 are incorrect solutions because the skewer 33 is in the initial state after these operations.

题意:有n个烤串,大概就是给烤串翻个面,当你翻第i个烤串时,它左边的k个烤串和右边的k个烤串,均会被翻面,求翻转的次数最少且所有烤串都翻面,输出选择的烤串序号

分析:其实就分两种情况,1:选择的每个烤串都在中间  2:考虑最左边和最右边的情况   ,就是找了一组数,模拟了一下过程

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int n,k;
while(~scanf("%d %d",&n,&k))
{
int t,tt,kk=;
t=n/(*k+);
tt=n%(*k+);
if(tt==)
{
printf("%d\n",t);
printf("%d",k+);
kk=*k++k+;
for(int i=;i<=t;i++)
{
printf(" %d",kk);
kk+=k*+;
}
printf("\n");
}
else
{
printf("%d\n",t+);
if(tt<=k+)
{
printf("");
kk=*k+;
for(int i=;i<t+;i++)
{
printf(" %d",kk);
kk+=*k+;
}
if(n>tt)
printf(" %d\n",n-tt+);
}
else
{
printf("%d",tt-k);
kk=tt+k+;
for(int i=;i<=t+;i++)
{
printf(" %d",kk);
kk+=*k+;
}
printf("\n");
}
}
}
return ;
}

2018SDIBT_国庆个人第二场的更多相关文章

  1. 2018SDIBT_国庆个人第一场

    A - Turn the Rectangles CodeForces - 1008B There are nn rectangles in a row. You can either turn eac ...

  2. 本周进步要点20161023(含李笑来第二场live笔记要点)

    本周主要忙于去武汉参加iDOF2016智能数字油田会议,会上做了题为“油田SOA及云平台的系统思考与实践”的报告,为了准备这篇报告,用到了一些以前学过的知识,具体内容见“参加iDOF2016会议的收获 ...

  3. 2014百度之星预赛(第二场)——Best Financing

    2014百度之星预赛(第二场)--Best Financing Problem Description 小A想通过合理投资银行理財产品达到收益最大化.已知小A在未来一段时间中的收入情况,描写叙述为两个 ...

  4. Contest1592 - 2018-2019赛季多校联合新生训练赛第二场(部分题解)

    Contest1592 - 2018-2019赛季多校联合新生训练赛第二场 D 10248 修建高楼(模拟优化) H 10252 组装玩具(贪心+二分) D 传送门 题干 题目描述 C 市有一条东西走 ...

  5. 2018牛客暑期ACM多校训练营第二场(有坑未填)

    第二场终于等来学弟 开始(被队友带飞)的开心(被虐)多校之旅 A   run A题是一个递推(dp?)+前缀和 因为看数据量比较大 就直接上前缀和了 一个比较简单的递推 没有太多难点 签到题 需要注意 ...

  6. 2018牛客网暑假ACM多校训练赛(第二场)E tree 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round2-E.html 题目传送门 - 2018牛客多校赛第二场 E ...

  7. NOI.AC NOIP模拟赛 第二场 补记

    NOI.AC NOIP模拟赛 第二场 补记 palindrome 题目大意: 同[CEOI2017]Palindromic Partitions string 同[TC11326]Impossible ...

  8. DevOps Workshop 研发运维一体化(北京第二场) 2016.04.27

    北京不亏为首都,人才济济,对微软DevOps解决方案感兴趣的人太多.我们与微软公司临时决定再家一场培训. 我之前在博客中(DevOps Workshop 研发运维一体化第一场(微软亚太研发集团总部)h ...

  9. CTF-i春秋网鼎杯第二场misc部分writeup

    CTF-i春秋网鼎杯第二场misc部分writeup 套娃 下载下来是六张图片 直接看并没有什么信息 一个一个查看属性 没有找到有用信息 到winhexv里看一下 都是标准的png图片,而且没有fla ...

随机推荐

  1. jQuery版本问题,及事件源

    jQuery版本的分界线是2.0 2.0之前很多方法支持ie低版本,2.0之后就不支持了 工具:index() 指定元素的索引  (有参数) 不传参的情况下,父级元素下同级元素的排名,传参:指定元素的 ...

  2. shell 发送所有内容到会话

    在shell当中 工具 发送键输入到所有会话 会有新的发现

  3. [UE4]UMG和关卡坐标变换、旋转小地图

    一.优化上一节的蓝图,新建一个函数addFlagToCanvas(动态添加图标到Canvas) 二. 分析地图坐标系和UMG坐标系 要根据实际情况分析关卡坐标系. UserWidget中的坐标系 三. ...

  4. ODBC数据源管理器-》系统DSN-》没有....Microsoft Access Driver(*mdb,*,accdb)

    问题如标题: 解决方法:打开目录:“C:\Windows\SysWOW64”,双击该目录下的“odbcad32.exe”文件,就进去ODBC数据源管理界面了,现在这个界面中就有access的驱动了!

  5. Docker删除镜像

    docker images往往不知不觉就占满了硬盘空间,为了清理冗余的image,可采用以下方法: 1.进入root权限 sudo su 2.停止所有的container,这样才能够删除其中的imag ...

  6. Linux交换空间(swap space)

    每次安装Linux的时候,都会要求配置交换分区,那么这个分区是干嘛的呢?不设置这个分区有什么后果?如果一定要设置,设置多大比较合适?本篇将试图回答这些问题并尽量覆盖所有swap相关的知识. 下面的所有 ...

  7. es6基础(7)--函数扩展

    { //有默认值的后面如果有参数必须要有默认值 function test(x,y="world"){ console.log(x,y) } test('hello');//hel ...

  8. mybatis-plus 从2.x到3.x升级指南

      Mybatis-Plus mybatis-plus 2.x 到 3.x 有以下改进 分页查询可以直接返回Ipage<T>的子类(下面会有详细使用说明) Wrapper<T> ...

  9. Java基本知识进阶

    1.static 2.代码块 3.继承 4.抽象类 5.接口 6.多态 7.包 8.权限修饰符 9.内部类 10.字节码 11.包装类 12.装箱&拆箱 13.正则表达式 14.异常 15.反 ...

  10. [Unity动画]03.动画事件

    1.找到动画,添加动画事件 2.在脚本中添加回调方法 TestAnimator.cs using UnityEngine; public class TestAnimator : MonoBehavi ...