-------------------昨天打的重现赛,感觉是我打的发挥的最好的一场比赛了,六题都一次AC。那么就来总结一下吧

题目链接:http://codeforces.com/contest/1133

A .Middle of the Contest

sol:简单模拟,注意一下跨天的情况就好了。

  • 模拟

    #include "bits/stdc++.h"
    using namespace std;
    int main() {
    int h1, m1, h2, m2, k;
    scanf("%d:%d%d:%d", &h1, &m1, &h2, &m2);
    // 把第二个时间加24小时,就能保证第二个时间比第一个时间大
    k = (m2 - m1 + (h2 + - h1) * ) % ( * ) >> ;
    m1 += k;
    h1 = (h1 + m1 / ) % ;
    m1 %= ;
    printf("%02d:%02d", h1, m1);
    return ;
    }

B .Preparation for International Women's Day

sol:如果(a + b) % k == 0,那么(a % k) + (b % k) == 0 || (a % k) + (b % k) == k。注意等于0的情况不要忽略掉。遍历一遍,对于第d[i],查看是否在前面出现过还未配对的余数和d[i]余数相加等于0或k的情况。

  • 同余

    #include "bits/stdc++.h"
    using namespace std;
    const int MAXN = ;
    int n, k, v, ans;
    int cnt[MAXN];
    int main() {
    scanf("%d%d", &n, &k);
    for (int i = ; i <= n; i++) {
    scanf("%d", &v);
    v %= k;
    if (cnt[(k - v) % k]) {
    ans += ;
    cnt[(k - v) % k]--;
    } else {
    cnt[v]++;
    }
    }
    printf("%d\n", ans);
    return ;
    }

C .Balanced Team

sol:尺取法,先排序,定义l = r = 1。然后让l和r一起往右移。

  • 尺取法

    #include "bits/stdc++.h"
    using namespace std;
    const int MAXN = 2e5 + ;
    int arr[MAXN], n, ans;
    int main() {
    scanf("%d", &n);
    for (int i = ; i <= n; i++) {
    scanf("%d", &arr[i]);
    }
    sort(arr + , arr + + n);
    int l = , r = ;
    while (r <= n) {
    while (arr[r] - arr[l] > ) l++;
    ans = max(ans, r - l + );
    r++;
    }
    printf("%d\n", ans);
    return ;
    }

D .Zero Quantity Maximization

sol:首先换个姿势看这个问题,c[i] = d * a[i] + b[i],求c数组0最多有几个,那么我让题目变成c[i] = a[i]和b[i]的比。求相同比最多的次数。用map计数就行了。但是这个比不能用double来计,会产生精度丢失。所以我是用pair来计比的。还有就要说说这题的样例了,a[i] == 0这种属于特殊数据怎么能放到样例里呢,虽然我一开始也没考虑到。注意约分的时候a[i]为0的情况;

  • 这题考细心

    #include "bits/stdc++.h"
    using namespace std;
    typedef pair<int, int> PII;
    const int MAXN = 2e5 + ;
    map<PII, int> mp;
    int a[MAXN], b[MAXN];
    int ans, n, k, g;
    int main() {
    scanf("%d", &n);
    for (int i = ; i <= n; i++)
    scanf("%d", &a[i]);
    for (int i = ; i <= n; i++)
    scanf("%d", &b[i]);
    for (int i = ; i <= n; i++) {
    if (a[i] == ) {
    k += (b[i] == );
    continue;
    }
    g = __gcd(a[i], b[i]);
    a[i] /= g, b[i] /= g;
    mp[{a[i], b[i]}]++;
    ans = max(ans, mp[{a[i], b[i]}]);
    }
    printf("%d\n", ans + k);
    return ;
    }

E .K Balanced Teams

sol:动态规划,先sort一下。dp[i][j]表示从第i个队员到最后一个队员组成j个队伍最多的人数。

ps:除了动态规划的部分,其他的和C题都一样。不过数据范围比较小,尺取法不是关键考点。用暴力也能过。

  • 动态规划

    #include "bits/stdc++.h"
    using namespace std;
    const int MAXN = ;
    int arr[MAXN];
    int dp[MAXN][MAXN];
    int ans;
    int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = ; i <= n; i++)
    scanf("%d", &arr[i]);
    sort(arr + , arr + + n);
    for (int i = n; i >= ; i--) {
    int k = i;
    while (k <= n && arr[k] - arr[i] <= ) k++;
    for (int j = ; j <= m; j++) {
    dp[i][j] = max(dp[i + ][j], k - i + dp[k][j - ]);
    ans = max(ans, dp[i][j]);
    }
    }
    printf("%d\n", ans);
    return ;
    }

F1 .Spanning Tree with Maximum Degree

sol:找到度数最大的节点,以度数最大的节点为起点bfs遍历全图

  • 图算法

    #include "bits/stdc++.h"
    using namespace std;
    const int MAXN = 2e5 + ;
    vector<int> edge[MAXN];
    int maxdg, pos;
    bool use[MAXN];
    void bfs(int pos) {
    queue<int> que;
    que.push(pos);
    use[pos] = true;
    while (!que.empty()) {
    pos = que.front();
    que.pop();
    for (int i = ; i < edge[pos].size(); i++) {
    if (!use[edge[pos][i]]) {
    printf("%d %d\n", pos, edge[pos][i]);
    que.push(edge[pos][i]);
    use[edge[pos][i]] = true;
    }
    }
    }
    }
    int main() {
    int n, m, u, v;
    scanf("%d%d", &n, &m);
    for (int i = ; i <= m; i++) {
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
    if (edge[u].size() > maxdg) {
    maxdg = edge[u].size();
    pos = u;
    }
    if (edge[v].size() > maxdg) {
    maxdg = edge[v].size();
    pos = v;
    }
    }
    bfs(pos);
    return ;
    }

CF-544:部分题目总结的更多相关文章

  1. CF 题目选做

    写省选的题目对noip没什么大用 关键是 细节题或者是思考题比较重要 练思维自然是CF比较好了 把我见到的比较好的CF题放上来刷一刷. LINK:Complete the projects 就是说一个 ...

  2. CF 219D 树形DP

    CF 219D [题目链接]CF 219D [题目类型]树形DP &题意: 给一个n节点的有向无环图,要找一个这样的点:该点到其它n-1要逆转的道路最少,(边<u,v>,如果v要到 ...

  3. 跟着xiaoxin巨巨做cf

    cf 385 C. Bear and Prime Numbers 题目大意:有一个数列{xi},每次给出一个询问[l, r],即问 S(l ,r)是l和r之间的素数,f(p)表示数列{xi}中整除p的 ...

  4. Codeforces Round #379 (Div. 2) 解题报告

    题目地址 本次CF是在今天早上深夜进行,上午有课就没有直接参加.今天早上上课坐到后排参加了virtual participation.这次CF前面的题目都非常的水,不到10分钟就轻松过了前两题,比较郁 ...

  5. Miaomiao's Geometry

    HDU 4932  Bestcoder Problem Description There are N point on X-axis . Miaomiao would like to cover t ...

  6. Codeforces Round #221 (Div. 2) C. Divisible by Seven(构造 大数除法 )

    上几次的一道cf题. 题目:http://codeforces.com/contest/376/problem/C 性质: (4)a与b的和除以c的余数(a.b两数除以c在没有余数的情况下除外),等于 ...

  7. 【小TIP】记录各种错误【更新中】

    最好程序一遍通过,为了提高代码能力,这里将用TIP的形式记录来犯过的错误.不断更新中. *已经转移到闪存.. [150214]WA:检查是否数组开小了. [150212]WA:如果程序中有乘号,需要留 ...

  8. Codeforces Round #242 (Div. 2) &lt;A-D&gt;

    CF424 A. Squats 题目意思: 有n(n为偶数)个x和X,求最少的变换次数,使得X的个数为n/2,输出变换后的序列. 解题思路: 统计X的个数ans,和n/2比較,少了的话,须要把n/2- ...

  9. [CF1107E]Vasya and Binary String【区间DP】

    题目描述 Vasya has a string s of length n consisting only of digits 0 and 1. Also he has an array a of l ...

  10. CF1131F Asya And Kittens(Kruskal重构树,启发式合并)

    这题难度1700,我感觉又小了…… 这题虽然没几个人是用kruskal重构树的思想做的,但是我是,所以我就放了个kruskal重构树的标签. 题目链接:CF原网 题目大意:有一个长为 $n$ 的排列, ...

随机推荐

  1. Redis的数据结构和对象。

    一.简单动态字符串(simple dynamic string--SDS) Redis使用SDS表示字符串值,键值对都用SDS实现.SDS中的字符数组buf以空字符串结尾,好处是可以直接重用一部分C字 ...

  2. javaweb06 文件的下载

    1. 如何修改小工具或框架的源代码 ? 1). 原则: 能不修改就不修改. 2). 修改的方法: > 修改源代码, 替换 jar 包中对应的 class 文件. > 在本地新建相同的包, ...

  3. 18. docker 容器部署 python-redis

    1. 编写 Vagrantfile 并创建虚拟机 并虚拟机绑定外部 192.168.205.10:8888 ip:port # -*- mode: ruby -*- # vi: set ft=ruby ...

  4. RFC文档(http部分)

    Request For Comments(RFC),是一系列以编号排定的文件.文件收集了有关互联网相关信息,以及UNIX和互联网社区的软件文件.目前RFC文件是由Internet Society(IS ...

  5. LeetCode——714. 买卖股票的最佳时机含手续费.

    给定一个整数数组 prices,其中第 i 个元素代表了第 i 天的股票价格 :非负整数 fee 代表了交易股票的手续费用. 你可以无限次地完成交易,但是你每次交易都需要付手续费.如果你已经购买了一个 ...

  6. PAT Advanced 1029 Median (25) [two pointers]

    题目 Given an increasing sequence S of N integers, the median is the number at the middle position. Fo ...

  7. Linux--Centos下搭建Git服务器

    参考:http://kimi.it/370.html   http://blog.csdn.net/wave_1102/article/details/47779401 开始直接用 yum insta ...

  8. 项目在eclipse中正常,在idea中报错

    一直用的eclipse,但公司很多员工用的都是idea,便想试试,谁知导入maven项目后一直报错,最后发现编译后target中没有dao中的xml文件,导致监听器加载资源时一直报错, 最后经过反复查 ...

  9. 9. Dockerfile 实际操作 (把 python app 打包成 image 并运行)

    1. 创建并进入 flask-hello-world mkdir flask-hello-world && cd flask-hello-world 2. 编写 python 文件 a ...

  10. 2.windows-oracle实战第二课 -用户管理

    创建用户:在oracle中创建一个用户有create user语句,一般是具有dba(数据库管理员)的权限才能使用.用户创建在所在的实例数据库中. 给用户修改密码:passw 给别人修改密码需要dba ...