zoukankan      html  css  js  c++  java
  • Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0

    A. Between the Offices

    题目意思:小明是一个高管,经常出差,如果他从S地飞往F地的次数大于从F地飞往S地,他会感到十分的开心。

    题目思路:暴力扫一遍,记下字符串中SF子串和FS子串的数量,然后判断其大小,就可以得出答案了

    题目链接:http://codeforces.com/contest/867/problem/A

    代码:

     1 /* ***********************************************
     2 Author        :xiaowuga
     3 Created Time  :2017年10月02日 星期一 12时09分34秒
     4 File Name     :A.cpp
     5 ************************************************ */
     6 #include <bits/stdc++.h>
     7 #define mem(s,ch) memset(s,ch,sizeof(s))
     8 typedef long long LL; 
     9 #define inf 0x3f3f3f3f 
    10 const long long N=1000000;
    11 const long long mod=1e9+7;
    12 using namespace std;
    13 int main(){
    14     ios::sync_with_stdio(false);cin.tie(0);
    15     int n;
    16     string q;
    17     cin>>n;
    18     cin>>q;
    19     int c1=0,c2=0;
    20     for(int i=1;i<q.size();i++){
    21         if(q[i]=='F'&&q[i-1]=='S') c1++;
    22         else if(q[i]=='S'&&q[i-1]=='F') c2++;
    23     }
    24     if(c1>c2) cout<<"YES"<<endl;
    25     else cout<<"NO"<<endl;
    26     return 0;
    27 }
    View Code

    B. Save the problem!

    题目意思:类似于反向完全背包,过去是给出要凑的零钱数量,和各种硬币的额度,让你求有多少种不同的组合方式,现在倒过来,给你有多少这种组合方式,让你给出一种方案(包括的要凑的零钱数,面额的种类,各种面额的大小)

    题目思路:MDZZ,完全靠大胆猜想找规律,直接看代码吧!

    代码:

     1 /* ***********************************************
     2 Author        :xiaowuga
     3 Created Time  :2017年10月02日 星期一 12时09分34秒
     4 File Name     :A.cpp
     5 ************************************************ */
     6 #include <bits/stdc++.h>
     7 #define mem(s,ch) memset(s,ch,sizeof(s))
     8 typedef long long LL; 
     9 #define inf 0x3f3f3f3f 
    10 const long long N=1000000;
    11 const long long mod=1e9+7;
    12 using namespace std;
    13 int main(){
    14     ios::sync_with_stdio(false);cin.tie(0);
    15     int n;
    16     string q;
    17     cin>>n;
    18     cin>>q;
    19     int c1=0,c2=0;
    20     for(int i=1;i<q.size();i++){
    21         if(q[i]=='F'&&q[i-1]=='S') c1++;
    22         else if(q[i]=='S'&&q[i-1]=='F') c2++;
    23     }
    24     if(c1>c2) cout<<"YES"<<endl;
    25     else cout<<"NO"<<endl;
    26     return 0;
    27 }
    View Code

    C. Ordering Pizza

    题目意思:给出N和S,表示现在有N个人,每个披萨有S块,现在给出每个人想要吃的披萨数量,和每吃一块type1的披萨会得到a点快乐值,每吃一块type2的披萨会得到b点快乐值。现在问在买最少的披萨的情况下,如果和让大家快乐值的和最大。

    题目思路:贪心思路,尽量让喜欢吃type1披萨的人吃type1披萨,喜欢吃type2披萨的人吃type2披萨,那我们就让他们都吃自己更喜欢吃的披萨,计算需要type1数量多少快(p块),type2数量多少块(块),然后对分别对S取膜(即p%=S,q%=S)如果p+q>S,说明一块披萨不够分,我们需要买两块,所以很明显我们买两块不同的披萨,就可以满足所有都全部吃上自己更喜欢吃的披萨,否则我们只能买一块披萨,说明一些人不能吃上自己最喜欢吃的披萨了,那现在我们就需要考虑到底是买哪一种披萨比较好了,处于贪心的思想,我们肯定是让对于两种披萨的喜欢差别不明显的人(即abs(a-b)比较小),不能吃上自己最喜欢的披萨,这样带来的损失是最小的,然后判断让喜欢吃type1的吃上type2,还是喜欢吃type2吃上type1哪个损失更小减掉就好了。

    代码:

     1 /* ***********************************************
     2 Author        :xiaowuga
     3 Created Time  :2017年10月02日 星期一 14时28分30秒
     4 File Name     :C.cpp
     5 ************************************************ */
     6 #include <bits/stdc++.h>
     7 #define mem(s,ch) memset(s,ch,sizeof(s))
     8 typedef long long LL; 
     9 #define inf 0x3f3f3f3f 
    10 const long long mod=1e9+7;
    11 using namespace std;
    12 vector<pair<LL,LL> >v1,v2;
    13 int main(){
    14     ios::sync_with_stdio(false);cin.tie(0);
    15     LL N,S;
    16     cin>>N>>S;
    17     LL s,a,b;
    18     LL ans=0;
    19     LL p=0,q=0;
    20     //ans=总数,p(a>b)的总数,q(a<b)的总数
    21     for(int i=1;i<=N;i++){
    22         cin>>s>>a>>b;
    23         if(a>b){
    24             ans+=s*a;
    25             p+=s;
    26             v1.push_back(make_pair(a-b,s));
    27         }
    28         else{
    29             ans+=s*b;
    30             q+=s;
    31             v2.push_back(make_pair(b-a,s));
    32         }
    33     }
    34     p%=S;q%=S;
    35     if(p+q>S){//那肯定type1,type2各买一个啦
    36         cout<<ans<<endl;
    37         return 0;
    38     }
    39     sort(v1.begin(),v1.end());
    40     sort(v2.begin(),v2.end());
    41     LL x=0,y=0;
    42     for(auto it:v1){
    43         x+=min(it.second,p)*it.first;
    44         p-=min(it.second,p);
    45     }
    46     for(auto it:v2){
    47         y+=min(it.second,q)*it.first;
    48         q-=min(it.second,q);
    49     }
    50     cout<<ans-min(x,y)<<endl;
    51     return 0;
    52 }
    View Code
  • 相关阅读:
    第三方库添加记录
    xcode之语法高亮效果消失解决办法
    将excel记录导入ms sql
    eWebEditor在IE8,IE7下所有按钮无效之解决办法
    关于对数据库中重复记录的操作
    javascript如何取得RadioButtonList的值
    水晶报表分页并自动插入空白行
    如何防止SQL注入
    VC++视频教程下载地址
    如何显示最近过生日的记录
  • 原文地址:https://www.cnblogs.com/xiaowuga/p/7623002.html
Copyright © 2011-2022 走看看