Problem#A Carrot Cakes

vjudge链接[here]

(偷个懒,cf链接就不给了)

  题目大意是说,烤面包,给出一段时间内可以考的面包数,建第二个炉子的时间,需要达到的面包数,问建炉子是否合理。

  玄学 & 智商题,可能是因为我智商不够,所以在我决定休息的时候被hank掉了。。。(纠正一个错误,是fst掉的)

  输NO的情况大概是当炉子建好后,考完第一波的时间,任务已经或刚好完成。

Code

 /**
  * Codeforces
  * Problem#799A
  * Accepted
  * Time:15ms
  * Memory:8k
  */
 #include<iostream>
 #include<fstream>
 #include<sstream>
 #include<algorithm>
 #include<cstdio>
 #include<cstring>
 #include<cstdlib>
 #include<cctype>
 #include<cmath>
 #include<ctime>
 #include<map>
 #include<stack>
 #include<set>
 #include<queue>
 #include<vector>
 using namespace std;
 typedef bool boolean;
 #define inf 0xfffffff
 #define smin(a, b) (a) = min((a), (b))
 #define smax(a, b) (a) = max((a), (b))
 template<typename T>
 inline boolean readInteger(T& u) {
     char x;
     ;
     );
     )    {
         ungetc(x, stdin);
         return false;
     }
     if(x == '-') {
         aFlag = -;
         x = getchar();
     }
      + x - ');
     u *= aFlag;
     ungetc(x, stdin);
     return true;
 }

 int n, t, k, d;

 inline void work() {
     readInteger(n);
     readInteger(t);
     readInteger(k);
     readInteger(d);
     ;
     if(turns * k > n)
         puts("NO");
     else if(turns * k == n && (d == t || turns * t <= d + t))
         puts("NO");
     else
         puts("YES");
 }

 int main() {
     work();
     ;
 }

Problem#A


Problem#B T-shirt buying

vjudge链接[here]

  题目大意是说,每件衣服有两面,每面有个颜色,有些人要来买,他只买存在一面有他喜欢的颜色且价格最低的一个,输出每个人付的钱,没有买到输出-1。

  用个set,依题意乱搞就好了。(每场比赛貌似都是b题稳AC)

Code

 /**
  * Codeforces
  * Problem#799B
  * Accepted
  * Time:296ms
  * Memory:14964k
  */
 #include<iostream>
 #include<fstream>
 #include<sstream>
 #include<algorithm>
 #include<cstdio>
 #include<cstring>
 #include<cstdlib>
 #include<cctype>
 #include<cmath>
 #include<ctime>
 #include<map>
 #include<stack>
 #include<set>
 #include<queue>
 #include<vector>
 using namespace std;
 typedef bool boolean;
 #define inf 0xfffffff
 #define smin(a, b) (a) = min((a), (b))
 #define smax(a, b) (a) = max((a), (b))
 template<typename T>
 inline boolean readInteger(T& u) {
     char x;
     ;
     );
     )    {
         ungetc(x, stdin);
         return false;
     }
     if(x == '-') {
         aFlag = -;
         x = getchar();
     }
      + x - ');
     u *= aFlag;
     ungetc(x, stdin);
     return true;
 }

 typedef class Tshirt {
     public:
         int p;
         int id;

         Tshirt() {        }
         Tshirt(int p, int id):p(p), id(id) {    }

         boolean operator < (Tshirt b) const {
             if(p != b.p) return p < b.p;
             return id < b.id;
         }
 }Tshirt;

 int n, m;
 int* prices;
 int *color1, *color2;

 multiset<Tshirt> ps[];

 inline void init() {
     readInteger(n);
     prices = )];
     color1 = )];
     color2 = )];
     ; i <= n; i++)
         readInteger(prices[i]);
     ; i <= n; i++) {
         readInteger(color1[i]);
         ps[color1[i] - ].insert(Tshirt(prices[i], i));
     }
     ; i <= n; i++) {
         readInteger(color2[i]);
         if(color1[i] != color2[i])
             ps[color2[i] - ].insert(Tshirt(prices[i], i));
     }
 }

 inline void solve() {
     int c;
     readInteger(m);
     while(m--) {
         readInteger(c);
         c--;
         ) {
             printf("-1 ");
         } else {
             multiset<Tshirt>::iterator t = ps[c].begin();
             printf("%d ", t->p);
             ) {
                 ps[color1[t->id] - ].erase(ps[color1[t->id] - ].find(Tshirt(t->p, t->id)));
             } ) {
                 ps[color2[t->id] - ].erase(ps[color2[t->id] - ].find(*t));
             }
             ps[c].erase(t);
         }
     }
 }

 int main() {
     init();
     solve();
     ;
 }

Problem#B


Problem#C Fountains

vjudge链接[here]

  C题思路不是很难,很好想,结果写炸了。。。

  第一种情况,买两个不同购买方式的物品,贪心就好了。

  第二种情况,买两个购买方式相同的物品,先按价格从小到大拍一道序,然后记录一个能延伸到的一个最远的物品r,每次i++时要用while循环去更新r,接着剩下的事交给线段树查最大值就好了。两种购买方式的物品都做一下就好了。

  当然,写炸的缘故

  1.自己坑自己。。sort的cmpare函数改了后没有改for循环的顺序(第一种情况比较懒,开始就写了就不想改了)

  2.少特判当某种购买方式的物品不存在的情况,然后建树就挂了,MLE。

Code

 /**
  * Codeforces
  * Problem#799C
  * Accepted
  * Time:62ms
  * Memory:6300k
  */
 #include<iostream>
 #include<fstream>
 #include<sstream>
 #include<algorithm>
 #include<cstdio>
 #include<cstring>
 #include<cstdlib>
 #include<cctype>
 #include<cmath>
 #include<ctime>
 #include<map>
 #include<stack>
 #include<set>
 #include<queue>
 #include<vector>
 using namespace std;
 typedef bool boolean;
 #define inf 0xfffffff
 #define smin(a, b) (a) = min((a), (b))
 #define smax(a, b) (a) = max((a), (b))
 template<typename T>
 inline boolean readInteger(T& u) {
     char x;
     ;
     );
     )    {
         ungetc(x, stdin);
         return false;
     }
     if(x == '-') {
         aFlag = -;
         x = getchar();
     }
      + x - ');
     u *= aFlag;
     ungetc(x, stdin);
     return true;
 }

 typedef class MyPair {
     public:
         int c;
         int p;

         MyPair(, ):c(c), p(p) {    }
 }MyPair;

 typedef class SegTreeNode {
     public:
         int val;
         SegTreeNode* l, *r;

         SegTreeNode():val(), l(NULL), r(NULL) {        }

         inline void pushUp() {
             val = max(l->val, r->val);
         }
 }SegTreeNode;

 typedef class SegTree {
     public:
         SegTreeNode* root;

         SegTree() {        }
         SegTree(int n, MyPair*& lis) {
             build(root, , n, lis);
         }

         void build(SegTreeNode*& node, int l, int r, MyPair*& lis) {
             node = new SegTreeNode();
             if(l == r) {
                 node->val = lis[l].c;
                 return;
             }
             ;
             build(node->l, l, mid, lis);
             build(node->r, mid + , r, lis);
             node->pushUp();
         }

         int query(SegTreeNode*& node, int l, int r, int ql, int qr) {
             ;
             if(l == ql && r == qr) {
                 return node->val;
             }
             ;
             if(qr <= mid)    return query(node->l, l, mid, ql, qr);
             , r, ql, qr);
             int a = query(node->l, l, mid, ql, mid);
             , r, mid + , qr);
             return max(a, b);
         }

         void clear(SegTreeNode*& node) {
             if(node->l)    clear(node->l);
             if(node->r)    clear(node->r);
             delete node;
         }
 }SegTree;

 int n;
 int C, D;
 MyPair *cs, *ds;
 , cnd = ;
 , bd = -;
 SegTree stc, stdd;

 inline void init() {
     readInteger(n);
     readInteger(C);
     readInteger(D);
     cs = )];
     ds = )];
     int a, b;
     char x;
     ; i <= n; i++) {
         readInteger(a);
         readInteger(b);
         getchar(); x = getchar();
         if(x == 'C' && b <= C)
             cs[++cnc] = MyPair(a, b);
         else if(x == 'D' && b <= D)
             ds[++cnd] = MyPair(a, b);
     }
 }

 boolean cmp1(const MyPair& a, const MyPair& b) {
     if(a.c != b.c) return a.c > b.c;
     return a.p < b.p;
 }

 boolean cmp2(const MyPair& a, const MyPair& b) {
     if(a.p != b.p) return a.p < b.p;
     return a.c > b.c;
 }

 ;

 inline void solve() {
     )
         sort(cs + , cs + cnc + , cmp1);
     )
         sort(ds + , ds + cnd + , cmp1);
     ; i <= cnc; i++)
         if(cs[i].p <= C) {
             bc = cs[i].c;
             break;
         }
     ; i <= cnd; i++)
         if(ds[i].p <= D) {
             bd = ds[i].c;
             break;
         }
      && bd != -)
         res = bc + bd;

     )
         sort(cs + , cs + cnc + , cmp2);
     )
         sort(ds + , ds + cnd + , cmp2);
     int r = cnc;
     if(cnc) {
         stc = SegTree(cnc, cs);
         ; i <= r; i++) {
             , a1 = ;
             while(cs[i].p + cs[r].p > C)    r--;
             if(i > r)   break;
             )
                 a0 = stc.query(stc.root, , cnc, , i - );
             if(i < cnc)
                 a1 = stc.query(stc.root, , cnc, i + , r);
              && a1 == )    continue;
             smax(res, max(a0, a1) + cs[i].c);
         }
     }

     r = cnd;
     if(cnd) {
     stdd = SegTree(cnd, ds);
         ; i <= r; i++) {
             , a1 = ;
             while(ds[i].p + ds[r].p > D)    r--;
             if(i > r)    break;
             )
                 a0 = stdd.query(stdd.root, , cnd, , i - );
             if(i < cnd)
                 a1 = stdd.query(stdd.root, , cnd, i + , r);
              && a1 == )    continue;
             smax(res, max(a0, a1) + ds[i].c);
         }
     }
     printf("%d", res);
 }

 int main() {
     init();
     solve();
     ;
 }

Problem#C

Codeforces Round#413 Problem A - C的更多相关文章

  1. Codeforces Round #413 (Div1 + Div. 2) C. Fountains(树状数组维护最大值)

    题目链接:https://codeforces.com/problemset/problem/799/C 题意:有 c 块硬币和 d 块钻石,每种喷泉消耗硬币或钻石中的一种,每个喷泉有一个美丽值,问建 ...

  2. codeforces Round 286# problem A. Mr. Kitayuta's Gift

    Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked ...

  3. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)

    A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

  4. Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心

    After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...

  5. Educational Codeforces Round 21 Problem D(Codeforces 808D)

    Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...

  6. Educational Codeforces Round 21 Problem A - C

    Problem A Lucky Year 题目传送门[here] 题目大意是说,只有一个数字非零的数是幸运的,给出一个数,求下一个幸运的数是多少. 这个幸运的数不是最高位的数字都是零,于是只跟最高位有 ...

  7. Codeforces Round #413, rated, Div. 1 + Div. 2 C. Fountains(贪心 or 树状数组)

    http://codeforces.com/contest/799/problem/C 题意: 有n做花园,有人有c个硬币,d个钻石 (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100  ...

  8. C.Fountains(Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)+线段树+RMQ)

    题目链接:http://codeforces.com/contest/799/problem/C 题目: 题意: 给你n种喷泉的价格和漂亮值,这n种喷泉题目指定用钻石或现金支付(分别用D和C表示),C ...

  9. Educational Codeforces Round 32 Problem 888C - K-Dominant Character

    1) Link to the problem: http://codeforces.com/contest/888/problem/C 2) Description: You are given a ...

随机推荐

  1. POJ - 1101 The Game dfs

    题意:给你一个地图,上面有一些‘X',给你起点终点,让你输出从起点到终点的路径中转向(改变方向)次数最少的路径,注意,不能穿过别的’X'并且可以超过边界 题解:关于超过边界,只要在外围多加一圈‘ ’. ...

  2. ArcGIS API for javascript开发笔记(五)——GP服务调用之GP模型的发布及使用详解

    感谢一路走来默默陪伴和支持的你~~~ ----------------欢迎来访,拒绝转载---------------- 关于GP模型的制作请点我! 一.GP发布 ArcGIS Desktop可以作为 ...

  3. JS闭包中的循环绑定处理程序

    前几天工作中写前端js代码时,遇到了遍历元素给它添加单击事件.就是这个问题让我整整调了一个下午.最后还是下班回家,上网查资料才知道怎么解决的. (PS:之前也在<jQuery基础教程>第四 ...

  4. BUG笔记:Firefox select选项右侧边框没了

    Firefox 的default select在某些情况下右侧边框会消失.截图如下: 这个目前为止没有看到有任何解决方案,HACK也没有...囧... 有高人知道吗?

  5. linux 安装mysql yum方式

    centos 6 #二进制rpm包安装 yum -y install mysql-server mysql centos7 mariadb和mysql一样的 只是一个分支 防止 mysql 被Orac ...

  6. 仿照hibernate封装的一个对数据库操作的jdbc工具类

    package project02_Order_management.util; import java.io.IOException; import java.lang.reflect.Field; ...

  7. 阻止提交按钮的默认 action

    使用 preventDefault() 函数来阻止对表单的提交. 示例代码如下: <html><head><script type="text/javascri ...

  8. 主成分分析 PCA算法原理

    对同一个体进行多项观察时,必定涉及多个随机变量X1,X2,…,Xp,它们都是的相关性, 一时难以综合.这时就需要借助主成分分析 (principal component analysis)来概括诸多信 ...

  9. testng入门教程10 TestNG参数化测试

    在TestNG的另一个有趣的功能是参数测试.在大多数情况下,你会遇到这样一个场景,业务逻辑需要一个巨大的不同数量的测试.参数测试,允许开发人员运行同样的测试,一遍又一遍使用不同的值. TestNG让你 ...

  10. 对于session,request,cookie的理解

    session和request的生命周期 首先是session,比如我们在实现一个购物车功能时,在某一页面(这里称为页面A)选择了一些购物的商品,添加到购物车.那么当我们选择完成后点击我的购物车时会跳 ...