Codeforces Round #437 (Div. 2, based on Memsql start[c]up 3.0-round 2)

Source: Internet
Author: User
Tags memsql



Problem A



Between the offices



Water problem, water a water.


 
 
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n;
 4 char s[200];
 5 int main()
 6 {
 7     cin>>n;
 8     int cnt1=0,cnt2=0;
 9     scanf("%s",s);
10     for(int i=0;i<n-1;i++)
11     {
12         if(s[i]==‘S‘ && s[i+1]==‘F‘) cnt1++;
13         else if(s[i]==‘F‘ && s[i+1]==‘S‘) cnt2++;
14     }
15     if(cnt1>cnt2) puts("YES");
16     else puts("NO");
17     return 0;
18 }
View Code





Problem B



Save the problem!



give you the number n, let you give a sum of money m, and the type of money N, ask for these kinds of money



The number of species that make up M is N.






Idea: I was constructed with 5 and 22 kinds of money, we consider the composition of 10 is only two kinds, one is 2 2 2 2 2, the other is



5 5, then 20 is three kinds, 30 is four, 40 is five, has been so constructed, forgot to consider a situation WA once ...


 
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n;
 4 int main()
 5 {
 6     scanf("%d",&n);
 7     if(n==1)
 8     {
 9         puts("1 1");
10         puts("1");
11         return 0;
12     }
13     printf("%d 2\n",(n-1)*10);
14     puts("5 2");
15     return 0;
16 }
View Code





Promblem C



Ordering Pizza



There are now n people need to eat si slice pizza, a total of two kinds of pizza A, a, I personally eat a slice a pizza obtained



The pleasure value is ai,b for bi, a slice of pizza can be divided into s slices, we need to buy the fewest pizzas and ask you what the maximum pleasure value is.






Idea: Let's get everyone to eat a pizza with a good value and then count the number of slices of a pizza and the number of slices in B pizza,



A and B to the S to take the film, the rest is uncertain, if a+b>s buy two kinds of pizza each one, if a+b<=s



Then buy a pizza, both of which are simulated to fetch a large number of pleasant values.


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
ll _abs(ll x)
{
    if(x>=0) return x;
    else return -x;
}
struct node
{
    ll s,a,b;
    bool operator < (const node &rhy)const
    {
        return _abs(a-b)<_abs(rhy.a-rhy.b);
    }
}p[N];
ll n,S;
ll work(ll c1,ll c2)
{
    ll ans=0;
    if(c1)
    {
        for(int i=0;i<n;i++)
        {
            if(p[i].a<p[i].b) continue;
            if(p[i].s>=c1) ans+=c1*(p[i].a-p[i].b);
            else ans+=p[i].s*(p[i].a-p[i].b);
            c1-=p[i].s;
            if(c1<=0) break;
        }
    }
    else
    {
        for(int i=0;i<n;i++)
        {
            if(p[i].a>=p[i].b) continue;
            if(p[i].s>=c2) ans+=c2*(p[i].b-p[i].a);
            else ans+=p[i].s*(p[i].b-p[i].a);
            c2-=p[i].s;
            if(c2<=0) break;
        }
    }
    return ans;
}
int main()
{
    cin>>n>>S;
    ll sum=0,ans=0;
    ll res1=0,res2=0;
    for(int i=0;i<n;i++)
    {
        scanf("%I64d%I64d%I64d",&p[i].s,&p[i].a,&p[i].b);
        ans+=p[i].s*max(p[i].a,p[i].b);
        if(p[i].a>=p[i].b) res1+=p[i].s;
        else res2+=p[i].s;
    }
    res1=res1%S; res2=res2%S;
    if(res1+res2>S)
    {
        printf("%I64d\n",ans);
        return 0;
    }
    ll res=1e18;
    sort(p,p+n);
    res=min(res,work(0,res2));
    res=min(res,work(res1,0));
    printf("%I64d\n",ans-res);
    return 0;
}
View Code





Problem E



Buy Low Sell High



To give you some stock price per day, every day you can choose to buy, sell, or do nothing, ask you



The maximum amount of profit.






Idea: puzzles, I will not! To maintain the minimum value with the priority queue, we take a number B, if this number is higher than the heap top



Element A is small, then B is added to the priority queue, if B is larger than a, delete a, add two B, (b-a) join ans,



The first B is the equivalent of turning a into B and the second b being itself.


 
 
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=3*1e5+5;
 4 int n,a[N];
 5 int main()
 6 {
 7     scanf("%d",&n);
 8     for(int i=1;i<=n;i++) scanf("%d",&a[i]);
 9     priority_queue<int,vector<int>,greater<int> > Q;
10     long long ans=0;
11     for(int i=1;i<=n;i++)
12     {
13         if(Q.empty())
14         {
15             Q.push(a[i]);
16             continue;
17         }
18         int t=Q.top();
19         if(t>=a[i]) Q.push(a[i]);
20         else
21         {
22             ans+=a[i]-t;
23             Q.pop();
24             Q.push(a[i]); Q.push(a[i]);
25         }
26     }
27     printf("%I64d\n",ans);
28     return 0;
29 }
View Code





Codeforces Round #437 (Div. 2, based on Memsql start[c]up 3.0-round 2)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.