Codeforces Round #105 (Div. 2) ABCDE

A. Insomnia cure

题解:

水,暴力一下就行了

代码:

#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 SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=100010;

ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
//-----------------------------------------------------------------------------

int a[maxn];

int main()
{
    int k,l,m,n,d;
    cin>>k>>l>>m>>n>>d;
    for(int i=k;i<=d;i+=k) a[i]=1;
    for(int i=l;i<=d;i+=l) a[i]=1;
    for(int i=m;i<=d;i+=m) a[i]=1;
    for(int i=n;i<=d;i+=n) a[i]=1;
    int sum=0;
    for(int i=1;i<=d;i++) if(a[i]) sum++;
    cout<<sum<<endl;
}

B. Escape

题解:

追击问题,也挺水的。

代码:

#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 SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=100010;

ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
//-----------------------------------------------------------------------------

int a[maxn];

int main()
{
   double p,d,t,f,c,tmp;
   int cnt=0;
   cin>>p>>d>>t>>f>>c;
   if(p>=d||p*t>=c) cout<<0<<endl;
   else
   {
         tmp=p*t;
         while(tmp<c)
         {
              double t1=tmp/(d-p);
              if(tmp+p*t1>=c) break;
              cnt++;
              tmp+=p*t1;
              t1=tmp/d;
              tmp+=p*(t1+f);
         }
         cout<<cnt<<endl;
   }
   return 0;
}

C. Terse princess

题解:

构造一个数组,要求有a个比他之前的全部的数和大。b个比他之前的任意一个都大(前者优先级高于后者)

注意a<=15,是不会超过50000

贪心构造就行了,在构造时有个trick,在t[1]=1,t[2]=2时,这算比他之前的全部的数和大

代码:

#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 SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=110;

ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
//-----------------------------------------------------------------------------

int a[maxn];

int main()
{
   int n,c,b;
   cin>>n>>c>>b;
   a[1]=1;
   int sum=1,tmp=1;
   if(c+1==n&&n!=1)
   {
        cout<<-1<<endl;
        return 0;
   }
   if(n==1)
   {
       cout<<1<<endl;
       return 0;
   }
   for(int i=1;i<=b;i++)
   {
         a[++tmp]=sum+1;
         sum+=a[tmp];
   }
   if(b==0) a[++tmp]=1;
   for(int i=1;i<=c;i++) a[++tmp]=a[tmp-1]+1;
   for(int i=1;i<=tmp;i++) cout<<a[i]<<" ";
   for(int i=tmp+1;i<=n;i++) cout<<1<<" ";
   cout<<endl;
   return 0;
}

D. Bag of mice

题解:

概率dp.

dp[i][j]表示公主在面对i个白鼠,j个黑鼠,赢的概率。具体看注释

代码:

#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 SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=110;

ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
//-----------------------------------------------------------------------------

double dp[1010][1010];//dp[i][j]表示公主面对i个白鼠和j个黑鼠赢的概率 

int w,b;

int main()
{
    cin>>w>>b;
    dp[0][0]=0.0;
    for(int i=1;i<=w;i++) dp[i][0]=1.0;
    for(int i=1;i<=b;i++) dp[0][i]=0.0;
    for(int i=1;i<=w;i++)
    {
        for(int j=1;j<=b;j++)
        {
            dp[i][j]+=(double)i/(i+j);//直接选白鼠
            if(j==1) continue;//如果选黑鼠,但是黑鼠只有一个,不可能赢
            if(j>2)  dp[i][j]+=(double)j/(i+j)*(double)(j-1)/(i+j-1)*(double)(j-2)/(i+j-2)*dp[i][j-3];//公主选黑鼠,龙选黑鼠,掉落黑鼠
            dp[i][j]+=(double)j/(i+j)*(double)(j-1)/(i+j-1)*(double)i/(i+j-2)*dp[i-1][j-2];//公主选黑鼠,龙选黑鼠,掉落白鼠
        }
    }
    cout<<setprecision(9)<<dp[w][b]<<endl;
    return 0;
}

E. Porcelain

题解:

预处理出每个书架选j个时的最大值。然后就是类似多重背包了

如何预处理?暴力一下即可。先求前缀和,然后枚举

代码:

#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 SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=110;

ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
//-----------------------------------------------------------------------------

int a[maxn][maxn],pre[maxn][maxn],dp[maxn][10010],sz[maxn];

int main()
{
     int n,m,tmp;
     cin>>n>>m;
     for(int i=1;i<=n;i++)
     {
         cin>>sz[i];
         for(int j=1;j<=sz[i];j++)
         {
             cin>>pre[i][j];
             pre[i][j]+=pre[i][j-1];
         }
         a[i][0]=0;
         for(int j=1;j<=sz[i];j++)
         for(int k=0;k<=j;k++) a[i][j]=max(a[i][j],pre[i][k]+pre[i][sz[i]]-pre[i][sz[i]-(j-k)]);
     }
     for(int i=1;i<=n;i++)
     for(int j=0;j<=m;j++)
     for(int k=0;k<=min(j,sz[i]);k++) dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i-1][j-k]+a[i][k]));
     cout<<dp[n][m]<<endl;
     return 0;
}
时间: 2024-10-08 03:27:44

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

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 #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 #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 #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

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

题目链接:http://codeforces.com/contest/415 A. Mashmokh and Lights time limit per test:1 second memory limit per test:256 megabytes Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are index

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

比赛链接:http://codeforces.com/contest/519 这场的题目实在有点水...前三题直接贴代码了 A. A and B and Chess time limit per test:1 second memory limit per test:256 megabytes A and B are preparing themselves for programming contests. To train their logical thinking and solve p