-------------------昨天打的重现赛,感觉是我打的发挥的最好的一场比赛了,六题都一次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. Java并发分析—Lock

    1.Lock 和 Condition 当使用synchronied进行同步时,可以在同步代码块中只用常用的wait和notify等方法,在使用显示锁的时候,将通过Condition对象与任意Lock实 ...

  2. android 根据距离区分 点击跟滑动事件

    public void onClick(View v) { if (isclick) Log.i(TAG, "onclick"); } }); } float distance = ...

  3. i春秋2020新春公益赛WP

    Re Factory 主函数fork了一个子进程,父进程添加了一个信号处理器用于比对input,然后死循环挂起.子进程读入input,然后调用了关键函数. 跟进关键函数,发现是从一段内存中读取数据,然 ...

  4. fatal error C1189: #error: "You must define TF_LIB_GTL_ALIGNED_CHAR_ARRAY for your compiler."

    使用VS开发tensorflow的C++程序的时候,就可能会遇上这个问题,解决方法是在引入tensoflow的头文件之前添加: #define COMPILER_MSVC #define NOMINM ...

  5. POJ 1655 Balancing Act【树的重心模板题】

    传送门:http://poj.org/problem?id=1655 题意:有T组数据,求出每组数据所构成的树的重心,输出这个树的重心的编号,并且输出重心删除后得到的最大子树的节点个数,如果个数相同, ...

  6. 计蒜客 置换的玩笑(DFS)

    传送门 题目大意: 小蒜头又调皮了.这一次,姐姐的实验报告惨遭毒手. 姐姐的实验报告上原本记录着从 1 到 n 的序列,任意两个数字间用空格间隔.但是“坑姐”的蒜头居然把数字间的空格都给删掉了,整个数 ...

  7. Storm 重启排查

    Storm实战常见问题及解决方案 https://www.cnblogs.com/catkins/p/5302634.html Storm 重启排查(续) https://www.iteye.com/ ...

  8. MyBatis从入门到精通(第5章):MyBatis代码生成器

    jdk1.8.MyBatis3.4.6.MySQL数据库5.6.45.Eclipse Version: 2019-12 M2 (4.14.0) MyBatis从入门到精通(第5章):MyBatis代码 ...

  9. 从[Greenplum 6.0] 1分钟安装尝鲜开始

    Greenplum目前6版本目前已经迭代了几个小版本了,随着版本的更新,不断的有bug被修复. 打算试用的朋友可以入手了. 作为开年的第一个工作日的第一个帖子,必须从“开天辟地”的6.0开始.以下内容 ...

  10. Promoter complex|转录组水平RNA的复杂度|

    生命组学 Promoter complex Tata box识别位点 Enhancer加入之后增强转录 不确定性与确定性之间的关系,原因中存在这不确定性,但是结果表达又是确定的.因为promoter的 ...