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 直 ...
随机推荐
- API 自动化框架
API 自动化框架 个人认为接口自动化测试使用python语言编写更加简单,但所有接口自动化项目代码的思维都是一样的 1.项目包结构 1.case:存放用例数据的包,将所有用例数据以配置文件形式传入 ...
- java-方法重载、参数传递、
1.Java的方法重载overload:同一个类内,可以有多个同名的方法,只要参数不同即可(包括参数类型和个数.多类型顺序) 2.基本类型(8种:byte\short\int\long\double\ ...
- less的使用(好文章)
好文章链接:30分钟学会less 自己总结一下这篇文章中的几个关键字:变量.混合.函数.嵌套.@import 下面贴上自己照着上面写的一些代码: <template> <div cl ...
- Python001-操作MSSQL(Microsoft sql server)基础示例(一)
Python操作mssql server数据库可以通过pymssql或pyodbc实现的.此文以pymssql为例.Python操作MSSQL基本操作步骤如下所示: 获取数据库连接Connection ...
- React之ref
作为响应式开发框架React,我们知道他是数据驱动的,但有时候避免不了还是得动用到DOM操作,这个时候我们就可以用到ref:用法如下: 然后这样做有个弊端,当一个 ul 下面的 li 是动态添加的时候 ...
- ADB——模拟手机按键输入
基本命令 adb 模拟按键输入的命令主要通过 input 进行 Usage: input [<source>] <command> [<arg>...] The s ...
- RN启动报错,环境相关问题
启动RN的时候刚开始报错: The request was denied by service delegate (SBMainWorkspace) for reason: Security (&qu ...
- 使用Apache JMeter对SQL Server、Mysql、Oracle压力测试(一)
前段时间面试被问到了数据库方面的知识:比如选择什么样的数据库,如何优化,怎么加索引,于是想到了自己动手测试一下常用数据库的性能: 第一步,下载好JMeter之后打开运行.话说这个JMeter打开还真是 ...
- linux----------linux下安装rar和unrar命令
1.wget http://www.rarlab.com/rar/rarlinux-x64-4.2.0.tar.gz 2.tar xf rarlinux-x64-4.2.0.tar.gz 解压下 ...
- UGUI血条跟随
定义常量 public class Content { //当前UI分辨率 public const float UI_Width = 1366f; public const float UI_Hei ...