A.Middle of the Contest

考虑把输入的时间单位化成分钟,相加除以2就好了

#include<bits/stdc++.h>
using namespace std;
#define re register
#define sys system("pause");
inline int read(){
    re ,f=;char c=getchar();
    ;c=getchar();}
    )+(x<<)+(c^),c=getchar();
    return x*f;
}
int main(){
    ], b[], c[], d[];
    scanf(],&a[], &b[],&b[]);
    scanf(],&c[], &d[],&d[]);
    ] +  * b[];
    ] +  * d[];
    ] +  * a[];
    ] +  * c[];
    ;
    ;
    ;
    )>=)
        printf();
    else
        printf();
    )>=)
    printf();
    else
    printf();
    //sys
    ;
}

对不起,我zz了

不要那样输入,太麻烦了

换一个

撤回!

 #include<bits/stdc++.h>
 using namespace std;
 #define re register
 #define sys system("pause");
 inline int read(){
     re ,f=;char c=getchar();
     ;c=getchar();}
     )+(x<<)+(c^),c=getchar();
     return x*f;
 }
 int main(){
     int h1, h2, m1, m2;
     scanf("%d:%d", &h1,&m1);
     scanf("%d:%d", &h2,&m2);
     ;
     ;
     ;
     )>=)
         printf();
     else
         printf();
     )>=)
     printf();
     else
     printf();
     //sys
     ;
 }

看到这题的时候突然感觉很欢乐

浙大有个同学刚刚开始学C语言,问了我一道PAT上的题,说是不给用if,代码越简单越好,能减1ms就减1ms(逼得我开了快读,还真的减了1ms)

小老弟,怎么是你??????

B. Preparation for International Women's Day

这题,和手速赛day1的那道dp是一样的

链接:https://www.cnblogs.com/guaguastandup/p/10353720.html

取区间中相加可以被k整除的数的子序列,这题的子序列长度为2而已

公式:(a+b) mod c==((a mod c)+(b mod c) )mod c

WA7------->>>>因为当i==k-i的时候,那个c[i]的值,也有可能是奇数

我给忘了,只判断了c[0]的奇偶性

 #include<bits/stdc++.h>
 using namespace std;
 #define int long long
 #define re register
 #define sys system("pause");
 inline int read(){
     re ,f=;char c=getchar();
     ;c=getchar();}
     )+(x<<)+(c^),c=getchar();
     return x*f;
 }
 ;
 int a,ans;
 ];//这个是k数组
 int32_t main(){
     int n,k;
     n = read(),k = read();
     ; i <= n;i++){
         a = read();
         c[a % k]++; //统计k的同余数;
     }
     ; i <= (k+)>>;i++){
         int t = min(c[i], c[k - i]);
         if(i==k-i){
             t = t - t % ;
             c[i] -= t;
             ans += t;
         }
         else{
             ans += t*;
             c[i] -= t;
             c[k - i] -= t;
         }
     }
     ans += c[] - c[] % ;
     cout << ans;
     //sys
     ;
 }

C.Balanced Team

委屈,看成求最大分数且满足跨度小于5的人数的个数了,其实是求满足跨度为5的选取方案中,选取的最大人数

 #include<bits/stdc++.h>
 using namespace std;
 #define int long long
 #define re register
 #define sys system("pause");
 inline int read(){
     re ,f=;char c=getchar();
     ;c=getchar();}
     )+(x<<)+(c^),c=getchar();
     return x*f;
 }
 ;
 ,ans,n;
 int ruler(){
     ; l <= n;l++){//for循环用于枚举左端点
         &&r<=n)//满足条件的时候右端点右移
             r++;
         ans = max(ans, r-l);
     }
     return ans;
 }
 int32_t main(){
     n = read();
     ; i <= n;i++){
         a[i] = read();
     }
     sort(a + , a + n + );
     printf("%lld", ruler());
     //sys
     ;
 }

这题其实长得挺眼熟的,昨天下午cf的A题也可以那样写

适用于:连续区间+区间长度不定---->选取某符合条件的区间

D. Zero Quantity Maximization

这题其实也谈不上数论吧

思路就是a/b的个数大小,并且要考虑a元素为0/b元素为0/a和b均为0的情况

所以只是一个操作的问题

如果a==0,b==0,则答案的结果++

如果a==0,b!=0,则无论d的值是多少不能满足c==0

剩下的情况是一样的,只要把他们变成互质的数对,存到map里就好了

刚才在想,有没有什么,可以不自动排序的map,

我们需要的是按照键key查找值value并且进行修改的性质,但是在这题里面并不需要排序

分析一下样例吧:

3
13 37 39
1    2    3

(1,13)和(3,39)是一样的

那么把(3,39)和(1,13)存到一起————>计数

那么只要把3/3,39/3  得到(1,13)数对就好了

写个gcd函数

然后还发现了一个神奇的事

原来algorithm里面是有gcd函数的

好像叫这个__gcd

平时在算法竞赛里看到别人都是自己写的,不知道是不是因为调用这个函数会减慢速度呢?

 #include<bits/stdc++.h>
 using namespace std;
 #define int long long
 #define sys system("pause")
 #define scan(n) scanf("%I64d", &(n))
 #define prin(n) printf("%I64d", (n))
 #define fo(a, b) for (int i = (a); i <= (b);i++)
 ;
 int a[maxn], b[maxn],ans,add;
 map<pair<int,int>, int> m;
 int gcd(int a,int b){
      ? a : gcd(b,a%b);
 }
 int32_t main(){
     int n;
     scan(n);
     fo(, n) scan(a[i]);
     fo(, n) scan(b[i]);
     fo(,n){
         &&b[i]==)
             add++;
         &&b[i])continue;
         else{
             int g = gcd(a[i], b[i]);
             a[i] /= g, b[i] /= g;
             pair<int,int> p =make_pair(a[i], b[i]);
             m[p]++;
             ans = max(ans, m[p]);
         }
     }
     prin(ans + add);
     //sys;
     ;
 }

注意第27行

格式是m[make_pair(a,b)]++;

这个地方省略了insert的操作,直接用make_pair

我要撤回之前说的话,把第24行改成

int g=__gcd(a[i],b[i]);

(两个_)

时间反而会快一点

我继续撤回

这是最后一次撤回了!!!

第二个比第一个慢

第一个的速度和调用algorithm里面的__gcd是一样的

F1. Spanning Tree with Maximum Degree

生成树&最大度数

我,又把题给看错了

T^T

上次说好,读题少于三遍要给全国人民发红包的来着...?

但是超过三遍了,只是这题意它不进脑子啊!!!!!!!

其实这题说的是,要保证有一个最大度就行了,我还以为是确保尽量多的点都是最大度

好好读一下这句话

“Your task is to find any spanning tree of this graph such that the maximum degree over all vertices is maximum possible”

什么意思呢,就是输出的任意生成树的最大度,是原图里的最大度

所以

只要保证从最大度出发就好了

所以虽然存了度数,但其实只需要利用它找到最大度,然后就可以遍历了

思路要清晰

剩下的边可以任意选择

1.成环---->并查集

2.输出生成树---->vector<pair<int,int> >ans;

 #include<bits/stdc++.h>
 using namespace std;
 #define int long long
 #define scan(a) scanf("%I64d", &a)
 #define scann(a,b) scanf("%I64d%I64d",&a,&b)//cf貌似不可以用%lld,只能用%I64d
 #define sys system("pause")
 #define fo(a, b) for (int i = a; i <= b;i++)
 ;
 vector<pair<int, int> > ans;//用于输出答案,长度为n-1
 vector<pair<int, int> > edge;//用于储存每一条边,长度为m
 vector<pair<int, int> > v[maxn];//用于储存顶点相连的每一条边!是每一条
 int n, m, x, y, f[maxn], d[maxn];
 //并、查集&成环判断
 int find(int x){
     return f[x] == x ? x : f[x] = find(f[x]);
 }
 bool unionset(int x,int y){
     x = find(x);
     y = find(y);
     if(x!=y){
         f[y] = x;
         return true;//未成环,可进队列
     }
     else
         return false;//成环,不可进队列
 }
 //根据度的大小排序,并且不能成环
 int32_t main(){
     scann(n, m);

     fo(,m){//输入m条边
         scann(x, y);
         edge.push_back(make_pair(x, y));
         v[x].push_back(make_pair(x, y));
         v[y].push_back(make_pair(x, y));
         d[x]++, d[y]++;
     }

     ,maxi;
     fo(, n){
         f[i] = i;
         if(d[i]>maxx){// 只 需要找到度最大的那条边
             maxx = d[i];
             maxi = i;
         }
     }

     for(auto it:v[maxi]){//把最大度的那条边的所有边加进去,并且合并
         ans.push_back(it);
         unionset(it.first, it.second);
     }
     for(auto it:edge){//再从刚开始存入的那条边开始遍历,谁不成环,就把谁加进去
         if(unionset(it.first,it.second))
             ans.push_back(it);
     }
     //这里要注意的是,根本不用判断ans里面是不是存了n-1条边
     //因为超出n-1条边就会成环!!!!!!!!!!!!!!!!!!!!!!!!!!!!**
     //心中有党,脑里有图!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     for(auto it:ans)
         printf("%I64d %I64d\n", it.first, it.second);//输出顺序无所谓
     //sys;
     ;
 }

E.Balanced Teams

 #include<bits/stdc++.h>
 using namespace std;
 #define int long long
 #define sys system("pause")
 #define scan(n) scanf("%I64d", &(n))
 #define scann(n, m) scanf("%I64d%I64d", &(n), &(m))
 #define prin(n) printf("%I64d", (n))
 #define fo(a, b) for (int i = (a); i <= (b);i++)
 ;
 ;//
 int32_t main(){
     int n, k;
     scann(n, k);
     fo(, n) scan(a[i]);
     sort(a + , a + n + );
     ;
     ; r <= n;r++){//枚举右端点
         &&l<r)l++;
         ; m <= k;m++)
             dp[r][m] = max(dp[r - ][m], dp[l - ][m - ] + r - l + );
     }
     fo(, k) ans = max(ans, dp[n][i]);//在队伍数为i时可能有人数的最大值
     prin(ans);
     //sys;
     ;
 }

F2. Spanning Tree with One Fixed Degree

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sys system("pause")
#define scan(n) scanf("%I64d", &(n))
#define scann(n, m) scanf("%I64d%I64d", &(n), &(m))
#define prin(n) printf("%I64d", (n))
#define scannn(a,b,c) scanf("%I64d %I64d %I64d",&(a),&(b),&(c))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define mem(a) memset(a,0,sizeof(a))
#define prinspace printf("\n")
#define fo(a, b) for (int i = (a); i <= (b);i++)
;
int f[maxn], degree, d, cnt, n, m, x, y;
int find(int x){
    f[x] == x ?x: f[x] = find(f[x]);}
bool unionset(int x,int y){
    x = find(x), y = find(y);
    if(x!=y){
        f[x] = y;
        return true;
    }
    return false;
}
vector<pii> edge1, edge, v[maxn],ans,wron;
int32_t main(){
    scannn(n, m, degree);
    fo(,m){
        scann(x, y);
        ||y==)
            edge1.pb(mp(x, y));
        else
            edge.pb(mp(x, y));
    }
    if(edge1.size()<degree){
        printf("NO\n");
        sys;
        ;
    }
    fo(, n) f[i] = i;//不要忘了并查集初始化!
    for(auto it :edge)
        unionset(it.ff, it.ss);
    for(auto it:edge1){
        if(unionset(it.ff,it.ss)){
            cnt++;
            ans.pb(it);
        }
        else
            wron.pb(it);
    }
    if(cnt>degree){
        printf("NO\n");
        sys;
        ;
    }
    fo(,degree-cnt)
        ans.pb(wron[i]);
    fo(, n) f[i] = i;
    for(auto it:ans)
        unionset(it.ff, it.ss);
    for(auto it:edge)
        if(unionset(it.ff,it.ss))
            ans.pb(it);
        printf("YES\n");
        for(auto it:ans)
            printf("%I64d %I64d\n", it.ff, it.ss);
        sys;
        ;
}

div3加油!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Codeforces Round #544 (Div. 3)解题报告的更多相关文章

  1. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

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

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  3. Codeforces Round #380 (Div. 2) 解题报告

    第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...

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

    又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<];    ,m2=;    ;i ...

  5. Codeforces Round #281 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...

  6. Codeforces Round #277 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...

  7. Codeforces Round #276 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...

  8. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

  9. Codeforces Round #479 (Div. 3)解题报告

    题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...

随机推荐

  1. Python_tkinter(4)_上传文件

    1.上传单个文件 import tkinter as tk from tkinter import filedialog def upload_file(): selectFile = tk.file ...

  2. vs2017无法安装

    vs2017无法安装,无错误提示和日志 参考:https://blog.csdn.net/jq0123/article/details/83987686 但是解决方法不一样,运行安装程序没有提示,需要 ...

  3. css实现礼券效果

    <template> <div class="demo"> <div class="stamp stamp01"> < ...

  4. 2019春第六周作业Compile Summarize

    这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 在这里 我在这个课程的目标是 能够熟练掌握指针的用法 这个作业在那个具体方面帮助我实现目标 对指针的使用更加得心应手 参考文献与网址 C语 ...

  5. JS生成当前月份包括最近12个月内的月份

    var last_year_month = function() { var result = []; for(var i = 0; i < 12; i++) { var d = new Dat ...

  6. Mockito常用方法及示例

    Mockit是一个开源mock框架,官网:http://mockito.org/,源码:https://github.com/mockito/mockito 要使用Mockit,首先需要在我们工程中引 ...

  7. ubuntu16.04 mysql 开启远程连接

    首先保证自己的mysql安装是正常的,如果需要安装请参考 Ubuntu16.04重新安装MySQL数据库 第一步,远程访问赋予权限 方案一 首先用root用户登录mysql mysql -u root ...

  8. archlinux中安装Oracle12c的过程中遇到的问题

    INFO: : cannot find INFO: /usr/lib64/libpthread_nonshared.aINFO: INFO: genclntsh: Failed to link lib ...

  9. caffe-ssd需要安装opencv

    https://blog.csdn.net/xiaxiazls/article/details/52039473

  10. 一个spinner控件使用的实例

    布局文件 <?xml version="1.0" encoding="utf-8"?><android.support.constraint. ...