Codeforces Round #191 (Div. 2)

来源:互联网 发布:js混淆怎么读 编辑:程序博客网 时间:2024/05/29 09:35

A. Flipping Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Iahub got bored, so he invented a game to be played on paper.

He writes n integers a1, a2, ..., an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indicesi and j (1 ≤ i ≤ j ≤ n) and flips all valuesak for which their positions are in range[i, j] (that is i ≤ k ≤ j). Flip the value of x means to apply operation x = 1 -x.

The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 100). In the second line of the input there aren integers: a1, a2, ..., an. It is guaranteed that each of those n values is either 0 or 1.

Output

Print an integer — the maximal number of 1s that can be obtained after exactly one move.

Examples
Input
51 0 0 1 0
Output
4
Input
41 0 0 1
Output
4
Note

In the first case, flip the segment from 2 to 5 (i = 2, j = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].

In the second case, flipping only the second and the third element (i = 2, j = 3) will turn all numbers into 1.


题目大意:

我们现在必须翻转一个区间一次,使得0->1 1->0.

问最多翻转之后的1的个数。


思路:

O(n^3)暴力

#include<stdio.h>#include<string.h>#include<iostream>using namespace std;int a[150];int main(){    int n;    while(~scanf("%d",&n))    {        for(int i=1;i<=n;i++)scanf("%d",&a[i]);        int output=0;        for(int L=1;L<=n;L++)        {            for(int R=L;R<=n;R++)            {                int tmp=0;                for(int i=1;i<=n;i++)                {                    if(i<=R&&i>=L)                    {                        tmp+=1-a[i];                    }                    else tmp+=a[i];                }                output=max(output,tmp);            }        }        printf("%d\n",output);    }}

B. Hungry Sequence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting ofn integers.

A sequence a1,a2, ..., an, consisting of n integers, is Hungry if and only if:

  • Its elements are in increasing order. That is an inequality ai < aj holds for any two indicesi, j (i < j).
  • For any two indices i and j (i < j), aj must not be divisible by ai.

Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.

Input

The input contains a single integer: n (1 ≤ n ≤ 105).

Output

Output a line that contains n space-separated integersa1 a2, ..., an(1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that eachai must not be greater than10000000 (107) and less than1.

If there are multiple solutions you can output any one.

Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31

题目大意:


让你构造出来一个长度为N的严格递增子序列,使得任意a【j】%a【i】>1(j>i);


思路:


预处理出来1e5个素数即可。

任意两个素数的gcd肯定都是1.


Ac代码:

#include<stdio.h>#include<string.h>#include<math.h>using namespace std;int Array[150000];int Is_or[1500000];void init(){    memset(Is_or,0,sizeof(Is_or));    Is_or[0]=1;    Is_or[1]=1;    int a,b;    for(int j=2;j<sqrt(1500000);j++)    {        if(Is_or[j]==0)        for(int k=j+j;k<=1500000;k+=j)        {            Is_or[k]=1;        }    }    int cnt=0;    for(int i=2;i<=1500000-1;i++)    {        if(Is_or[i]==0)        {            Array[cnt++]=i;        }    }}int main(){    init();    int n;    while(~scanf("%d",&n))    {        for(int i=0;i<n;i++)        {            printf("%d ",Array[i]);        }        printf("\n");    }}

C. Magic Five
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by5. Note that, the resulting number may contain leading zeros.

Now Iahub wants to count the number of ways he can obtain magic number, modulo1000000007 (109 + 7). Two ways are different, if the set of deleted positions ins differs.

Look at the input part of the statement, s is given in a special form.

Input

In the first line you're given a string a (1 ≤ |a| ≤ 105), containing digits only. In the second line you're given an integerk (1 ≤ k ≤ 109). The plates is formed by concatenating k copies of a together. That isn = |ak.

Output

Print a single integer — the required number of ways modulo 1000000007 (109 + 7).

Examples
Input
12561
Output
4
Input
139902
Output
528
Input
5552
Output
63
Note

In the first case, there are four possible ways to make a number that is divisible by 5: 5, 15, 25 and 125.

In the second case, remember to concatenate the copies of a. The actual plate is 1399013990.

In the third case, except deleting all digits, any choice will do. Therefore there are26 - 1 = 63 possible ways to delete digits.


题目大意:


给你一个字符串,其真实字符串是给出的字符串重复K次的结果。

现在让你任意删除一些数字,使得剩余的部分是一个%5==0的数,允许有前导0.

问你有多少种删除的方式。


思路:


既然可以有前导0.

现在假设k==1的话,不难推出:Ans=Σ2^i(a【i】==0||a【i】==5);

那么此时K==2的话,也不难推出:Ans=Σ2^i(a【i】==0||a【i】==5)+2^len*Σ2^i(a【i】==0||a【i】==5)

那么此时K==3的话,也不难推出:Ans=Σ2^i(a【i】==0||a【i】==5)+2^len*Σ2^i(a【i】==0||a【i】==5)+2^(2*len)*Σ2^i(a【i】==0||a【i】==5)


那么我们设定Tmp=Σ2^i(a【i】==0||a【i】==5),那么最终的结果一定是:

Ans=Tmp*(1+2^len+2^(2*len)+2^(3*len)..................+2^((k-1)*len));

很显然,括号中的答案就是一个等比数列求和。


等比数列求和需要用到除法,所以我们需要使用逆元。


又因为数据比较大,我写的时候为了求稳同时使用了快速乘。


Ac代码:

#include<stdio.h>#include<string.h>using namespace std;#define ll __int64char a[1050000];const ll mod=1e9+7;ll kuaisucheng(ll a,ll b){    ll ans=0;    while(b)    {        if(b&1)        {            ans=(ans+a);            if(ans>=mod)ans-=mod;        }        a=(a+a);        if(a>=mod)a-=mod;        b/=2;    }    return ans;}ll kuaisumi(ll a,ll b){    a%=mod;    ll ans=1;    while(b)    {        if(b&1)        {            ans=kuaisucheng(ans,a);        }        a=kuaisucheng(a,a);        b/=2;    }    return ans;}ll extend_euclid(ll a,ll b,ll &x,ll &y){    if(b==0)    {        x=1,y=0;        return a;    }    else    {        ll r = extend_euclid(b,a%b,x,y);        ll t = x;        x = y;        y = t - (a/b)*y;        return r;    }}ll chufaqumo(ll fenzi ,ll fenmu){    ll x,y;    extend_euclid(fenmu,mod,x,y);    x=(x%mod+mod)%mod;    x=(x*fenzi+mod)%mod;    return x;}int main(){    while(~scanf("%s",a+1))    {        ll kk;        scanf("%I64d",&kk);        int n=strlen(a+1);        ll Right=chufaqumo((kuaisumi(2,n*kk)-1),(kuaisumi(2,n)-1));        ll Left=0;        for(int i=1;i<=n;i++)        {            if(a[i]=='5'||a[i]=='0')            Left+=kuaisumi(2,i-1);            Left%=mod;        }        ll ans=kuaisucheng(Left,Right);        printf("%I64d\n",ans);    }}

D.一道煞笔贪心Bfs T T.我是萌萌哒D题题解


E.状压Dp+Lowbit优化.我是萌萌哒E题题解











原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 凉鞋前面踢破了怎么办 尖头鞋前面折了怎么办 月子里宝宝蛋蛋破皮怎么办 军人在训练时想上侧所怎么办 被白蚂蚁咬了怎么办 被蚂蚁咬了起包怎么办 脚踢了石头肿了怎么办 脚大拇指踢肿了怎么办 被骨头咯到了疼怎么办 被开水烫着了疼怎么办 鞋子上踩了口香糖怎么办 鞋底踩到口香糖干了怎么办 鞋子不小心踩到口香糖怎么办 站久了膝盖痛怎么办 站久了脚底板痛怎么办 蛇疮好了以后痛怎么办 站久了脚趾痛怎么办 心脏被踢了一脚怎么办 从马背上摔下来怎么办 小孩蛋蛋碰撞后有积液怎么办 小孩蛋蛋大小不一样有积液怎么办 对派出所的笔录不服怎么办 蛋蛋让尿淹了发红有小红瘩达怎么办 手被皮筋弹肿了怎么办 手被皮筋勒肿了怎么办 皮筋把手挤肿了怎么办 猫被皮筋绑久肿了怎么办 抗链0高关节疼怎么办 近视800度老了怎么办 军检体重不达标怎么办 到交房租没有钱怎么办 房租没到期房东要收回怎么办 客户指定发快递我要怎么办? 跨境汇款被退回怎么办 汇款途径写错了怎么办 快递被菜鸟驿站退回怎么办 电脑登录账户已锁定怎么办 被外管局查到境外汇款买房怎么办 军校生复检被刷怎么办 企业私刻章拿去挂项目怎么办? 中通快递被退回怎么办