Codeforces Round #544 (Div. 3)解题报告
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)解题报告的更多相关文章
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- Codeforces Round #380 (Div. 2) 解题报告
第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...
- Codeforces Round #216 (Div. 2)解题报告
又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<]; ,m2=; ;i ...
- Codeforces Round #281 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...
- Codeforces Round #277 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...
- Codeforces Round #276 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...
- Codeforces Round #350 (Div. 2)解题报告
codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...
- Codeforces Round #479 (Div. 3)解题报告
题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...
随机推荐
- python基础之类的多态与多态性
原文链接:https://www.cnblogs.com/luchuangao/p/6739557.html 很多人喜欢将多态与多态性二者混为一谈,然后百思不得其解,其实只要分开看,就会很明朗. 一 ...
- 核心思想:决定你是富人还是穷人的11条标准(有强烈的赚钱意识,这也是他血液里的东西,太精彩了)good
原文地址:决定你是富人还是穷人的11条标准作者:谢仲华 1.自我认知 穷人:很少想到如何去赚钱和如何才能赚到钱,认为自己一辈子就该这样,不相信会有什么改变. 富人:骨子里就深信自己生下来不是要做穷人, ...
- 深度学习基础(五)ResNet_Deep Residual Learning for Image Recognition
ResNet可以说是在过去几年中计算机视觉和深度学习领域最具开创性的工作.在其面世以后,目标检测.图像分割等任务中著名的网络模型纷纷借鉴其思想,进一步提升了各自的性能,比如yolo,Inception ...
- Scala集合Map
在scala中Map分为可变长(mutable)和不可变长(immutable) /** * 不可变长map 长度一旦初始化,就不能在进行更改 */ // 通过箭头的方式创建map val map = ...
- STM32F103驱动GT911
0x00 引脚连接: // SCL-------PB10 // SDA-------PB11 // INT--------PB1 // RST--------PB2 IIC的SCL与SDA需要接上拉电 ...
- IntelliJ IDEA使用笔记
IntelliJ IDEA 2016.3.7激活 1.下载 JetbrainsCrack-2.10-release-enc.jar 链接:https://pan.baidu.com/s/1qVdhWg ...
- python迭代器的原理及应用
''''什么是迭代器?迭代的工具1.什么是迭代? 迭代是一个重复的过程,每一次重复都是基于上一次结果而进行的while True: print('hello world')像上面做这种单纯的重复并不是 ...
- Vue学习4:class与style绑定
说明:有些部分我只是相当于做一个学习笔记,加强记忆之用.所以可能阅读性不是那么强.如果有参考我这类博客的人,那么请见谅. 代码如下: <!DOCTYPE html> <html la ...
- 比NGINX更快:nginx-1.15.5 vs mongols-1.2.3
nginx是多进程web服务器的优秀代表. 本文要用mongols-1.2.3实现一个比nginx更快的多进程的web服务器. mongols是C++ 服务器基础设施库, 它的主要特性如下: tcp ...
- openwrt路由器进入安全模式
openwrt路由器型号:WNDR3800 一.实验背景 在pc机上通过xshell软件登录openwrt路由器,pc机通过网线与openwrt路由器的LAN接口相连.openwrt路由器自带两块无线 ...