zoukankan      html  css  js  c++  java
  • B计划 第六周

    都写到第六周了,还不让进A计划。。。。。。

    第一题: 买酱油,买五瓶送两瓶,买三瓶送一瓶。10元/瓶。给出钱数,问最多能买多少瓶酱油。

    第二题:教师取放钥匙,结构体排序,重载运算符。

    第三题:文件操作,字符串处理,查询。

    第四题:有向图的搜索。能达到点v的点数 + 点v可达到的点数 == 总点数n - 1。询问有多少个这样的点。

    第五题:维护线段树。

    6、Mahmoud and Ehab and the MEX

    7、Mahmoud and Ehab and the bipartiteness 二部图的搜索。
    8、唯一的雪花。set应用。大小为的数组,求区间[L, R]的长度,满足ai != a[j] (i != j且L <= i , j <= R).
    9、Gergovia的酒交易。持久化
    10、全部相加。小堆
    11、抄书,UVa 714 二分check答案.小心输出答案格式。
    12、cut integers. 注意模0错。
    13、Splitting A Linked List (25) 模拟链表,vector + 结构体。元素可能有重复的第五组测试数据,读入的元素不一定全在list中。
    14、Vertex Cover (25) 点覆盖。给一个点集合,若所有边至少有一个终点在该几何中,这个集合就是一个点覆盖集合。
    15、Emergency. Dijkstra算法。
    16、Counting Leaves. BFS, DFS ,树的层次序遍历。
    17、Maximum Subsequence 动态规划。
    18、Radix. 二分法。
    19、Waiting in line. queue应用。
    20、Deepest Root。 图的遍历。 计算连通分量个数
    21、Digital Libray map映射,STL使用。
    22、Hello World for U。 图形打印
    23、Password字符串处理
    24、Is it a Binary Search Tree. 二叉排序树
    25、String Subtraction 哈希散列。
    26、Hashing。二次探方法。
    27、Perfect Sequence.二分,
    28、Acute Stroke. BFS
    29、Social Clusters. 并查集
    30、Pre ans Post-order Traversals. 前序后序转中序。
     
     
     
     
    11、
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 using namespace std;
     6 const int N = 507;
     7 int a[N], n;
     8 bool v[N];
     9 int check(long long x) { //返回连续区间和不大于x的段数
    10     long long pre = 0, cnt = 1;
    11     for (int i= 1; i <= n; ++i) {
    12         if(pre + a[i] > x) {
    13             cnt++;
    14             pre = a[i];
    15         }
    16         else pre += a[i];
    17     }
    18     return cnt;
    19 }
    20 int main()
    21 {
    22     int T;
    23     scanf("%d", &T);
    24     while(T-- > 0) {
    25         int m;
    26         scanf("%d%d", &n, &m);
    27         long long R = 0, L = 0;
    28         for (int i = 1; i <= n; ++i) {
    29             scanf("%d", a + i);
    30             R += a[i];
    31             L = max(L, (long long)a[i]);
    32         }
    33         while(L <= R) {
    34             long long x = L + R >> 1;
    35             //printf("%lld %lld %lld %d
    ", L, R, x, check(x));
    36             if(check(x) > m) L = x + 1;
    37             else R = x - 1;
    38         }
    39         //cout << L << endl;
    40         long long suf = 0;
    41         memset(v, 0, sizeof v);
    42         for (int i = n; i >= 1; --i) {
    43             if(i < m) { //比如剩余3个数无法分成四部分,需要一个/
    44                 v[i] = 1; m--; //v[i] = true表示第i个数后面有一个/
    45                 suf = 0;
    46             }
    47             else {
    48                 if(suf + a[i] > L) {
    49                     suf = a[i];
    50                     v[i] = 1; m--;
    51                 }
    52                 else {
    53                     suf += a[i];
    54                 }
    55             }
    56         }
    57         for (int i = 1; i < n; ++i) {
    58             printf("%d ", a[i]);
    59             if(v[i]) printf("/ ");
    60         }
    61         printf("%d
    ", a[n]);
    62     }
    63 
    64     return 0;
    65 }
    View Code

      

  • 相关阅读:
    HTML-图片和多媒体
    HTML弹性布局
    HTML定位——绝对定位和相对定位、固定定位
    HTML定位和布局----float浮动
    CSS层叠
    HTML-css样式引用方式
    认识HTML和CSS
    原生js 进度条
    原生js文字滚动 滚动条
    时间轴
  • 原文地址:https://www.cnblogs.com/qinwenjie/p/7576499.html
Copyright © 2011-2022 走看看