A.先全部化成分钟数,取平均数之后化成正常时刻。

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int main(){
int h1,m1,h2,m2;
scanf("%d:%d %d:%d",&h1,&m1,&h2,&m2);
int num = (h2 - h1) * + (m2 - m1);
num /= ; m1 += num;
while(m1 >= ){
h1++;
m1 -= ;
}
printf("%02d:%02d",h1,m1);
return ;
}

A

B.所有数全部对K取余之后就能知道可以匹配他的兄弟是谁了,计数直接算即可。

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 2e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int a[maxn];
int num[maxn];
int main(){
Sca2(N,K);
for(int i = ; i <= N ; i ++){
scanf("%d",&a[i]);
a[i] %= K;
num[a[i]]++;
}
int ans = num[] / ;
for(int i = ; i + i <= K; i ++){
if(i + i == K) ans += num[i] / ;
else ans += min(num[i],num[K - i]);
}
Pri(ans * );
return ;
}

B

C.一个类似简化版的尺取即可。

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 2e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int a[maxn];
int main(){
Sca(N);
for(int i = ; i <= N ; i ++) Sca(a[i]);
sort(a + ,a + + N);
int s = ,t = ;
int ans = ;
for(int i = ; i <= N ; i ++){
while(t < N && a[t + ] - a[i] <= ) t++;
ans = max(ans,t - i + );
}
Pri(ans);
return ;
}

C

D.由于使每个位置取0的D有一个固定的数,map统计一下相同D的最大个数即可。

这里选择用结构体重载一下运算符处理,double 和 long double 都WA了,所以化成了分数最简比。

要注意如果要用map去重,不但要重载 == ,还有 <,最好可以每一个元素都在 < 里面讨论到,使得map排序结果可以确定

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const long double eps = 1e-;
const int maxn = 2e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
LL a[maxn],b[maxn];
struct Node{
LL x,y;
Node(){}
Node(LL x,LL y):x(x),y(y){}
friend bool operator == (Node a,Node b){
return a.x == b.x && a.y == b.y;
}
friend bool operator < (Node a,Node b){
if(a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
};
LL gcd(LL a,LL b){
return !b?a:gcd(b,a % b);
}
map<Node,int>P;
int main(){
Sca(N);
for(int i = ; i <= N ; i ++) scanf("%lld",&a[i]);
for(int i = ; i <= N ; i ++) scanf("%lld",&b[i]);
int ans = ,flag = ;
for(int i = ;i <= N ; i ++){
if(!a[i]){
if(!b[i]) flag++;
continue;
}
Node d;
if(!b[i]){
d = Node(,);
}else{
LL g = gcd(abs(a[i]),abs(b[i]));
int flag = ;
if(a[i] < ) flag *= -;
if(b[i] < ) flag *= -;
d = Node(flag * abs(b[i]) / g,abs(a[i]) / g);
}
P[d]++;
ans = max(ans,P[d]);
}
Pri(ans + flag);
return ;
}

D

E.C题的扩展,dp[i][j]记录有1 ~ j之间选i只队最多可以选多少人,直接递推即可。

5000 * 5000有很大MLE的风险,但是第一层i可以直接省略掉,空间复杂度为O(n)

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int a[maxn];
int pre[maxn];
int dp[maxn];
int main(){
Sca2(N,K);
for(int i = ; i <= N ; i ++) Sca(a[i]);
sort(a + ,a + + N);
int t = ;
for(int i = ; i <= N; i ++){
while(t <= N && a[t + ] - a[i] <= ){
t++; pre[t] = i;
}
}
for(int i = ; i <= K ; i ++){
for(int j = N; j >= ; j --){
dp[j] = max(dp[j],dp[pre[j] - ] + j - pre[j] + );
}
for(int j = ; j <= N ; j ++) dp[j] = max(dp[j],dp[j - ]);
}
Pri(dp[N]);
return ;
}

E

F1.取ind最多的点,将所有和他相邻的点率先加入树边,然后并查集处理加入余下的树边

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 2e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int ind[maxn];
int fa[maxn];
void init(){
for(int i = ; i <= N ; i ++) fa[i] = i;
}
int find(int t){
if(t == fa[t]) return t;
return fa[t] = find(fa[t]);
}
int Union(int a,int b){
a = find(a); b = find(b);
if(a == b) return ;
fa[a] = b;
return ;
}
PII E[maxn];
int main(){
Sca2(N,M); init();
for(int i = ; i <= M ; i ++){
int u,v; Sca2(u,v);
E[i].fi = u; E[i].se = v;
ind[u]++; ind[v]++;
}
int Max = ;
for(int i = ; i <= N ; i ++){
if(ind[Max] < ind[i]) Max = i;
}
int ans = ;
for(int i = ; i <= M ; i ++){
if(E[i].fi == Max || E[i].se == Max){
if(Union(E[i].fi,E[i].se)){
ans++;
printf("%d %d\n",E[i].fi,E[i].se);
}
}
}
for(int i = ; i <= M && ans < N - ; i ++){
if(Union(E[i].fi,E[i].se)){
ans++;
printf("%d %d\n",E[i].fi,E[i].se);
}
}
return ;
}

F1

F2.一开始以为点1出去的桥必须联通,其他任意,后来发现并不。

删除所有1相邻的边之后产生的连通分量,1需要有边和每一个连通分量有边,其余剩下的位置才是任意。

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 2e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
struct Edge{
int to,next;
bool cut;
}edge[maxn * ];
int head[maxn],tot;
int fa[maxn];
int sum;
void init(){
for(int i = ; i <= N ; i ++) head[i] = -;
tot = ;
}
int find(int x){
if(x == fa[x]) return x;
return fa[x] = find(fa[x]);
}
int Union(int a,int b){
a = find(a); b = find(b);
if(a == b) return ;
fa[a] = b; sum++;
return ;
}
void add(int u,int v){
edge[tot].to = v;
edge[tot].next = head[u];
edge[tot].cut = ;
head[u] = tot++;
}
int ind[maxn];
vector<PII>ans;
int main(){
Sca3(N,M,K); init();
for(int i = ; i <= N ; i ++) fa[i] = i;
for(int i = ; i <= M ; i ++){
int u = read(),v = read();
add(u,v); add(v,u);
if(u != && v != ) Union(u,v);
ind[u]++; ind[v]++;
}
for(int j = head[]; ~j ; j = edge[j].next){
if(Union(,edge[j].to)){
edge[j].cut = edge[j ^ ].cut = ;
}
}
sum = ;
for(int i = ; i <= N ; i ++) fa[i] = i;
for(int i = head[]; ~i; i = edge[i].next){
if(edge[i].cut && Union(,edge[i].to)){
ans.pb(mp(,edge[i].to));
K--;
}
}
for(int i = ; i <= N; i ++){
for(int j = head[i]; ~j; j = edge[j].next){
if((i == || edge[j].to == ) && K <= ) continue;
if(Union(edge[j].to,i)){
if(i == || edge[j].to == ) K--;
ans.pb(mp(i,edge[j].to));
}
}
}
if(sum < N - || K){
puts("NO");
if(M == ){
cout << sum << " " << K << endl;
}
return ;
}
puts("YES");
for(int i = ; i < ans.size(); i ++){
printf("%d %d\n",ans[i].fi,ans[i].se);
}
return ;
}

F2

codeforces-1133 (div3)的更多相关文章

  1. Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)

    Problem  Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...

  2. codeforces #579(div3)

    codeforces #579(div3) A. Circle of Students 题意: 给定一个n个学生的编号,学生编号1~n,如果他们能够在不改变顺序的情况下按编号(无论是正序还是逆序,但不 ...

  3. CodeForces 1029E div3

    题目链接 第一道场上自己做出来的E题...虽然是div3,而且是原题... 当时做完ABC,D题没有思路就去怼E了,然后发现貌似原题? 事实上就是原题... 给个原题链接... [HNOI2003]消 ...

  4. [Codeforces #615 div3]1294E Obtain a Permutation

    Before the Beginniing 本文为 Clouder 原创文章,原文链接为Click,转载时请将本段放在文章开头显眼处.如进行了二次创作,请明确标明. 由本人转载于博客园. 题意分析 C ...

  5. Codeforces #624 div3 C

    You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...

  6. Codeforces 1133 F2. Spanning Tree with One Fixed Degree 并查集+生成树

    好久没更新博客了,一直懒得动,这次更新一下. 题意大概是:给出一个图,求它的一个一号节点的度数恰好为D的生成树的方案. 一开始随便水了个乱搞贪心,不出意外并没有过. 仔细思考之后,对于这个问题我们可以 ...

  7. Twist the Permutation 数列的轮换题 Codeforces 776 div3

    这是一道比较经典的将数列中的数字轮换的题目,我们先看题干: 题干分析:先浅浅地分析一下题目是要我们干什么,我们会默认有一个已经升序排序地1~n的排列,然后我们会给定一个新排列是在原有排列的基础上进行o ...

  8. 记一次神奇的codeforces

    今天有一场codeforces的div3,时间挺合适,于是就想打.结果发现rating超过1600就不能报名.虽然shzr好久不打CF了而且很菜,但是毕竟还是到了1600的,于是和ZUTTER_一起用 ...

  9. CodeForces Round #527 (Div3) B. Teams Forming

    http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...

  10. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

随机推荐

  1. datatable的部分问题处理(动态定义列头,给某行添加事件,初始显示空数据)

    一.动态定义列头 在ajax中,用datatable再去重新配置列头,当然传回的数据中,要有对应放列头的键值对 我自定义了Mock数据,用于前端自己交互. 其中,rowdata用于存放传回的数据,co ...

  2. 我的Windows日常——炫酷的windows组件命令行打开方式

    regedit -------注册表编辑器 gpedit.msc-------组策略编辑器 secpol.msc--------本地安全策略 control ----------控制面板 cmd--- ...

  3. nexus 10 救砖 安装lineage OS 15 并 root

    因为平板自带的谷歌应用太烦人了,想root之后卸载它们. 一.root nexus 10 官方系统 1.把img拷贝到platform-tools(Android官网下载)文件夹 2.platform ...

  4. C# -- 使用FileInfo获取文件信息

    C# -- 使用FileInfo获取文件信息 1. 代码实现 static void Main(string[] args) { GetFileInfo(@"D:\Test.xlsx&quo ...

  5. 记录Nginx实现内容重定向的两种方式:rewrite和反向代理

    第一种:rewrite server { listen                80; server_name   www.test.org; root                  /te ...

  6. SharpZipLib压缩解压的使用

    项目中使用 Velocity 将模板和生成的动态内容(HTML.XML等)合并保存到redis数据库中,考虑到压缩的文件容量会比较小,方便传输而且存储所使用的空间也会比较小,所以要压缩一下,读取的时候 ...

  7. dicom错误解决

    https://github.com/pydicom/pydicom/issues/331 sudo apt-get install python-gdcm

  8. ASP.NET MVC 下自定义 JsonResult,使用 Json.NET 序列化 JSON

    直接贴代码了: using System; using System.Web.Mvc; using Newtonsoft.Json; namespace MvcSample.Extensions { ...

  9. Web后台快速开发框架

    Web后台快速开发框架 Coldairarrow 目录 目录 第1章    目录    1 第2章    简介    3 第3章    基础准备    4 3.1    开发环境要求    4 3.2 ...

  10. Net包管理NuGet(2)nuget包的生成方法

    1,下载NuGetPackageExplorer,可以下载运行源码,也可以直接下载安装包安装安装之后打开 设置好内容之后点击绿色的打钩保存然后操作右边空白处 然后点击File>Save;保存之后 ...