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. 动态材质实例(Dynamic Material Instance)

    转自:http://blog.csdn.net/panda1234lee/article/details/62041775 本例将通过 “靠近影响椅子的颜色” 来展示什么是 动态材质实例(Dynami ...

  2. 在线学习和在线凸优化(online learning and online convex optimization)—基础介绍1

    开启一个在线学习和在线凸优化框架专题学习: 1.首先介绍在线学习的相关概念 在线学习是在一系列连续的回合(rounds)中进行的: 在回合,学习机(learner)被给一个question:(一个向量 ...

  3. 成功设置open live writer

    mark一下,哈哈哈 https://www.cnblogs.com/chrisrockdl/

  4. Javascript异步编程的4种方法(阮一峰)

    转载: http://www.ruanyifeng.com/blog/2012/12/asynchronous%EF%BC%BFjavascript.html 你可能知道,Javascript语言的执 ...

  5. Python网络爬虫之requests模块

    今日内容 session处理cookie proxies参数设置请求代理ip 基于线程池的数据爬取 知识点回顾 xpath的解析流程 bs4的解析流程 常用xpath表达式 常用bs4解析方法 引入 ...

  6. 对于Servlet、Servlet容器以及一个Servlet容器-Tomcat

    Servlet.Servlet容器等内容讲解 转载自http://blog.csdn.net/iAm333 对于Servlet.Servlet容器以及一个Servlet容器-Tomcat这些概念讲解的 ...

  7. 部署django项目,sqlite3数据库出错sqlite3.NotSupportedError: URIs not supported

    如果遇到这个错误 sqlite3.NotSupportedError: URIs not supported 修改类似 该路径 的 base.py文件 /root/.virtualenvs/fkPy3 ...

  8. [UGUI]渲染层级关系

    参考链接: http://blog.csdn.net/meegomeego/article/details/42060389 Unity中的渲染顺序自上而下大致可以分为三层: 1.Camera层.可以 ...

  9. 6、申请发布(Distribution)证书和描述文件

    发布(Production)证书用于正式发布环境下使用,用于提交到Appstore审核发布. 申请发布(Production)证书 在“Certificates, Identifiers & ...

  10. 【HQL】窗口函数

    LAG LAG(col,n,DEFAULT) :与lead相反,用于统计窗口内往上第n行值.第一个参数为列名,第二个参数为往上第n行(可选,默认为1),第三个参数为默认值(当往上第n行为NULL时候, ...