Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] ​ 给你一个有向图,给用最少的颜色给每条边染色,要保证不存在一个环中的所有边都是同一个颜色. [Solution] ​ 用拓扑排序判断图中是否存在环,若图中不存在环,则所有边都是同一种颜色.否则,同一个环中,只要用两种颜色就可以满足题目条件,所以总的颜色数就是两种,对于一个环,一定会存在两种边:1.节点号小…
https://www.cnblogs.com/31415926535x/p/11601964.html 这场只做了前四道,,感觉学到的东西也很多,,最后两道数据结构的题没有补... A. Creating a Character 贪心加一堆判断就行了,,, #include <bits/stdc++.h> #define aaa cout<<233<<endl; #define endl '\n' using namespace std; typedef long l…
传送门 A. Creating a Character 设读入的数据分别为 $a,b,c$ 对于一种合法的分配,设分了 $x$ 给 $a$ 那么有 $a+x>b+(c-x)$,整理得到 $x>(b+c-a)/2$ 因为 $x \in [0,c]$ ,所以求一下区间交的大小即可,注意 (b+c-a) 可能小于 0 #include<iostream> #include<cstdio> #include<algorithm> #include<cstrin…
题意:https://codeforc.es/contest/1217/problem/D 给你一个有向图,要求一个循环里不能有相同颜色的边,问你最小要几种颜色染色,怎么染色? 思路: 如果没有环,那全是1:如果有环,那小到大的边为1,大到小的边为2. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>/…
https://codeforces.com/contest/1217 D:给定一个有向图,给图染色,使图中的环不只由一种颜色构成,输出每一条边的颜色 不成环的边全部用1染色 ps:最后输出需要注意,一个环上的序号必然是非全递增的,若有环且有一条边u->v,u的序号<v则输出1否则输出2(反过来也可以) 可以用dfs染色或者用拓扑排序做 顺便复习一下拓扑排序: 拓扑排序是将有向无环图的所有顶点排成一个线性序列,使得图中任意两个顶点u,v若存在u->v,那么序列中u一定在v前面. 了解一个…
C. The Number Of Good Substrings Problem Description: You are given a binary string s (recall that a string is binary if each character is either 0 or 1).Let f(t) be the decimal representation of integer t written in binary form (possibly with leadin…
Problem Description: You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads!Initially Zmei Gorynich has x heads. You can deal n types of blows. If you deal a blow of the i-th type,…
Problem Description: You play your favourite game yet another time. You chose the character you didn't play before. It has str points of strength and int points of intelligence. Also, at start, the character has exp free experience points you can inv…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;#define BUF_SIZE 100000bool IOerror=0;//加了读入挂才1900ms+卡ddl过的,不加读入代码tleT_Tinline char nc(){ static char buf[BUF_SIZE], *p1=buf+BUF_SIZE, *pend=buf+BUF_SIZE; if(p1==pend){ p1=buf; p…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[200007];int a[200007][20];int main(){ int t; cin>>t; while(t--){ cin>>s+1; int n=strlen(s+1); for(int i=0;i<=n;++i) for(int j=0;j<=18;++j) a[i][j]=0; for…