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. error lnk1158 无法运行rc.exe

    找到C:\Program Files (x86)\Windows Kits\8.0\bin\在运行一下rc.exe和rcdll.dll拷贝到D:\Soft\VS2015\VC\bin目录下.

  2. C# 图片识别

    项目需要识别图片上的信息,网上搜索试了Asprise-OCR.Microsoft Office Document Imaging(Office 2007) 组件实现两种方式,后者可以识别中文等其他语言 ...

  3. 常见MQTT服务器搭建与试用

    常见MQTT服务器搭建与试用   简介 MQTT(Message Queuing Telemetry Transport,消息队列遥测传输)是IBM开发的一个即时通讯协议,它比较适合于在低带宽.不可靠 ...

  4. Python从入坑到放弃!

    Python基础  python基础 python基础之 while 逻辑运算符 格式化输出等 python基础之 基本数据类型,str方法和for循环 python基础之 列表,元组,字典 pyth ...

  5. PHP防CC攻击代码

    PHP防CC攻击代码: empty($_SERVER['HTTP_VIA']) or exit('Access Denied'); //代理IP直接退出 session_start(); $secon ...

  6. jQuery动画方法

    下面介绍一些使用jQuery实现动画的方法: html中有如下代码: <button id="btn-box1">show</button> <but ...

  7. 软件测试第二次作业:初识JUNIT单元测试方法

    软件测试有很多分类,从测试的方法上可分为:黑盒测试.白盒测试.静态测试.动态测试   从软件开发的过程分为:单元测试.集成测试.确认测试.验收.回归等. 在众多的分类中,与开发人员关系最紧密的莫过于单 ...

  8. linux 消息队列

    消息队列,这个可是鼎鼎大名,经常在某些地方看见大家那个膜拜,那个,嗯,那个... 那就给个完整的例子,大家欣赏就行,我一直认为不用那个,嗯@ 这个队列的最大作用就是进程间通信,你要非搞个持久化,那也行 ...

  9. Leetcode Articles: Insert into a Cyclic Sorted List

    Given a node from a cyclic linked list which has been sorted, write a function to insert a value int ...

  10. asp.net导入后台代码

    public void Upload(string information){ int Bank = 0; for (int i = 0; i <Request.Files.Count; i++ ...