Codeforces Round #272 (Div. 2) ABCDE

A. Dreamoon and Stairs

题解:

首先写出尽可能2多的步数,然后判断能否%m,不能就加上最小的数使其能%m就行了

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define LL long long
#define CLR(x) memset(x,0,sizeof x)
#define MC(x,y) memcpy(x,y,sizeof(x))
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int> P;
const double eps=1e-9;
const int N=1e5+10;
const int M=1e3+10;
const int mod=1e9+7;
const int INF=1e9+10;

int n,m;

int main(){
    int n,m;
    cin>>n>>m;
    if(n<m) cout<<-1<<endl;
    else{
    int ans=n/2+(n%2==0?0:1);
    if(ans%m==0) cout<<ans<<endl;
    else{
        for(int i=1;i<m;i++){
            if((ans+i)%m==0){
                cout<<ans+i<<endl;
                break;
            }
        }
    }
    }
}

B.Dreamoon and WiFi

题解:

简单dp,递推搜索一下就行了

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define LL long long
#define CLR(x) memset(x,0,sizeof x)
#define MC(x,y) memcpy(x,y,sizeof(x))
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int> P;
const double eps=1e-9;
const int N=1e5+10;
const int M=1e3+10;
const int mod=1e9+7;
const int INF=1e9+10;

string s1,s2;
int cnt1,cnt,len;

void DP(int pos,int c){
      if(pos==len){
         if(c==cnt1) cnt++;
         return;
     }
     if(s2[pos]==‘+‘)  DP(pos+1,c+1);
     if(s2[pos]==‘-‘)  DP(pos+1,c-1);
     if(s2[pos]==‘?‘){
         DP(pos+1,c-1);
         DP(pos+1,c+1);
     }
}

int main(){
    cin>>s1>>s2;
    cnt1=0,cnt=0;
    len=s1.length();
    for(int i=0;i<len;i++) if(s1[i]==‘+‘) cnt1++;else cnt1--;
    int sum=1;
    for(int i=0;i<len;i++) if(s2[i]==‘?‘) sum*=2;
    DP(0,0);
    cout<<setprecision(15)<<(double)cnt/(double)sum<<endl;
    return 0;
}

C.Dreamoon and Sums

题解:

注意到x/b=x/b*b+x%b就行。然后注意每个计算位置都要计算取mod.....

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define LL long long
#define CLR(x) memset(x,0,sizeof x)
#define MC(x,y) memcpy(x,y,sizeof(x))
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int> P;
const double eps=1e-9;
const int N=1e5+10;
const int M=1e3+10;
const LL mod=1000000007;
const int INF=1e9+10;

LL a,b;

int main(){
    cin>>a>>b;
    LL k=((1LL+a)*a/2%mod*b%mod+a)%mod;
    LL sum=0;
    for(LL i=1;i<b;i++){
        sum+=i*k;
        sum%=mod;
    }
    cout<<sum<<endl;
}

D. Dreamoon and Sets

题解:

规律题,不多说

代码:

#include <iostream>
using namespace std;

int main(){
    int n,k;
    cin>>k>>n;
    cout<<(6*k-1)*n<<endl;
    for(int i=0;i<k;i++)cout<<n*(6*i+1)<<" "<<n*(6*i+2)<<" "<<n*(6*i+3)<<" "<<n*(6*i+5)<<endl;

}

E. Dreamoon and Strings

题解:

暴力处理每个位置,从后面到前面的第一个模板的位置,然后dp处理

参考博客http://www.cnblogs.com/qscqesze/p/5794709.html

代码:

//Coding by qscqesze
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2005;
char s1[maxn],s2[maxn];
int dp[maxn][maxn];
int len1,len2;
int solve(int x)
{
    if(x<len2)return maxn;
    int a=x,b=len2,tmp=0;
    while(a&&b)
    {
        if(s1[a]==s2[b])a--,b--;
        else tmp++,a--;
    }
    if(b==0)return tmp;
    else return maxn;
}
int main()
{
    scanf("%s%s",s1+1,s2+1);
    len1 = strlen(s1+1);
    len2 = strlen(s2+1);
    for(int i=0;i<=len1;i++)
        for(int j=0;j<=len1;j++)
            if(j>i)dp[i][j]=-3000;
    for(int i=1;i<=len1;i++)
    {
        int x=solve(i);
        for(int k=0;k<=len1;k++)
            dp[i][k]=max(dp[i][k],dp[i-1][k]);
        for(int k=0;k<=len1;k++)if(x<=k)
            dp[i][k]=max(dp[i][k],dp[i-x-len2][k-x]+1);
    }
    for(int i=0;i<=len1;i++)
        printf("%d ",dp[len1][i]);
    printf("\n");
}
时间: 2024-09-30 09:07:28

Codeforces Round #272 (Div. 2) ABCDE的相关文章

Codeforces Round #261 (Div. 2)[ABCDE]

Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden 题意: 一个正方形,它的边平行于坐标轴,给出这个正方形的两个点,求出另外两个点. 分析: 推断下是否平行X轴或平行Y轴,各种if. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: A.cpp * Create Date: 2014-0

Codeforces Round #264 (Div. 2)[ABCDE]

Codeforces Round #264 (Div. 2)[ABCDE] ACM 题目地址: Codeforces Round #264 (Div. 2) 这场只出了两题TAT,C由于cin给fst了,D想到正解快敲完了却game over了... 掉rating掉的厉害QvQ... A - Caisa and Sugar[模拟] 题意: Caisa拿s美元去超市买sugar,有n种sugar,每种为xi美元yi美分,超市找钱时不会找美分,而是用sweet代替,当然能用美元找就尽量用美元找.他

Codeforces Round #260 (Div. 2) ABCDE

A题逗比了,没有看到All ai are distinct. All bi are distinct. 其实很水的.. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 #define mnx 100002 8 9 10 struct latop{ 11 int p, q; 12 bo

Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi (超几何分布)

题目链接:Codeforces Round #273 (Div. 2) B. Dreamoon and WiFi 题意:"+"表示前进1个单位,"-"表示后退1个单位,问以0为起点经过S1,S2两个命令后达到的位置相同的概率. 思路:统计"+"和"-"的数量.如果S2中的"+"或者"-"比S1中的多,概率是0.其他条件下,形成的是超几何分布. AC代码: #include <std

Codeforces Round #531 (Div. 3) ABCDE题解

Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividing 题意: 给一个数n,然后要求你把1,2.....n分为两个集合,使得两个集合里面元素的和的差的绝对值最小. 题解: 分析可以发现,当n%4==0 或者 n%3==0,答案为0:其余答案为1.之后输出一下就好了. 代码如下: #include <bits/stdc++.h> using name

Codeforces Round #200 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/344 A. Magnets time limit per test:1 second memory limit per test:256 megabytes Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets inst

Codeforces Round #105 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/148 比较简单的一场,最长的一题也才写了30行多一点 A. Insomnia cure time limit per test:2 seconds memory limit per test:256 megabytes ?One dragon. Two dragon. Three dragon?, - the princess was counting. She had trouble falling asleep, and

Codeforces Round #272 (Div. 2)

A. Dreamoon and Stairs 题意:给出n层楼梯,m,一次能够上1层或者2层楼梯,问在所有的上楼需要的步数中是否存在m的倍数 找出范围,即为最大步数为n(一次上一级),最小步数为n/2+n%2 在这个范围里找即可 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<algorithm> 6 using n

Codeforces Round #186 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/313 A. Ilya and Bank Account time limit per test:2 seconds memory limit per test:256 megabytes Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obl