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 直 ...
随机推荐
- 64IE无法显示网页
1.碰到如下图情况ie浏览器打开之后显示不了网页,但是试了下电脑上其他的浏览器都可以正常的打开网页. 2.解决办法为:打开浏览器-选择“工具”-“Internet选项”-“高级”-重置,重启浏览器后能 ...
- 学号20175313 《实现Linux下cp XXX1 XXX2的功能(一)》第九周
目录 MyCP 一.题目要求 二.题目理解 三.需求分析 四.设计思路 五.伪代码分析 六.代码链接 七.代码实现过程中遇到的问题 八.运行结果截图 九.参考资料 MyCP 一.题目要求 编写MyCP ...
- 一次 Spark SQL 性能提升10倍的经历(转载)
1. 遇到了啥问题 是酱紫的,简单来说:并发执行 spark job 的时候,并发的提速很不明显. 嗯,且听我慢慢道来,啰嗦点说,类似于我们内部有一个系统给分析师用,他们写一些 sql,在我们的 sp ...
- 【技巧】-NO.123.数据处理技巧
Style:Mac Series:Java Since:2018-09-10 End:2018-09-10 Total Hours:1 Degree Of Diffculty:5 Degree Of ...
- locust压测rpc协议
这里主要是google的grpc接口进行压测的一个栗子. Locust是以HTTP为主要目标构建的. 但是,通过编写钩子触发器request_success和 request_failure事件的自定 ...
- Mybatis下的sql注入
以前只知道mybatis框架下,order by后面接的是列名是不能用#{},这样不起效果,只能用${},这样的话就可能产生sql注入.后来发现其实还有另外两种情况也是类似的: 1.order by ...
- Elasticsearch.安装(单节点)
Elasticsearch.安装(单节点) 环境Linux 7.x jdk 1.8 elasticsearch 5.x 环境目录结构(根目录多了两个文件夹): /resources /** 存放 ...
- Python_lambda
最近学习到python的lambda表达式也是匿名函数, lambda不需要使用def 语句这样标准的形式定义一个函数,并不需要花很多时间去额外定义一个不常用的函数.lambda的本省就是一个长度为一 ...
- 克隆Rockey6加密狗复制资料
克隆Rockey6加密狗复制资料下载 描述:Rockey6加密狗复制克隆方法Rockey6加密狗复制案例解析! 一.用OD加载DLL,并分析: 10001320 >/$ B8 4C140000 ...
- SSH的软链接后门
之前说过为了防止SSH的后面漏洞 , 升级到高版本的OpenSSH , 那也不能保证万无一失 经典后门 直接对sshd建立软连接 , 之后用任意密码登录即可 看下面操作 创建完软连接后 创建新的会 ...