感受

第一次参加CF的rating比赛,感觉还是非常exciting,前18分钟把AB切掉之后一直在考虑C题,结果最后还是没有想出来Orz

传送门

A

比较水的模拟,就是计算:\(\frac{z}{lcm(a,b)}\)

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, m, z;
int gcd(int n, int m) {
return m == 0 ? n : gcd(m, n%m);
} int main() {
cin >> n >> m >> z;
cout << (z/((ll)n*m/gcd(n, m)));
return 0;
}

B

水题。

#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000;
int main() {
int n, a[maxn];
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
if(n&1){
for(int i = 1; i <= n; i++) {
if(i & 1) {
cout << a[n-i+1];
}
else cout << a[i];
cout << ' ';
}
}
else {
for(int i = 1; i <= n/2; i++) {
if(i & 1) cout << a[n-i+1];
else cout << a[i];
cout << ' ';
}
for(int i = n/2+1; i <= n; i++) {
if(i & 1) cout << a[i];
else cout << a[n-i+1];
cout << ' ';
}
}
return 0;
}

C

考试的时候并没有切出来。。。

后来发现很简单。。。

题目大意

给出一颗树及各个点的颜色,求一个点,使得以该点为根时,其所有子树(不包括整棵树)颜色相同。

题解

解法1:\(O(n+m)\):如果有一条边,其两端颜色不同,那么不难得到必然有一个点是根,分别使用dfs检查即可。

解法2:\(O(n)\):统计所有颜色不同的边,如果有解,那么这些边一定有一个共同的端点,统计一下即可。

代码

考场tle代码

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
vector<int> G[maxn];
int n, c[maxn];
int color;
inline int read() {
int x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar();}
return x * f;
}
int vis[maxn];
bool dfs(int x) {
vector<int>::iterator it;
for(it = G[x].begin(); it != G[x].end(); it++) {
int &v = *it;
if(!vis[v]) {
vis[v] = 1;
if(c[v] != color) return false;
if(!dfs(v)) return false;
}
}
return true;
} bool check(int x) {
vector<int>::iterator it;
for(it = G[x].begin(); it != G[x].end(); it++) {
color = c[*it];
vis[x] = 1;
if(!dfs(*it)) return false;
}
return true;
}
int main() {
scanf("%d", &n);
for(int i = 1; i < n; i++) {
int u = read(), v = read();
G[u].push_back(v);
G[v].push_back(u);
}
set<int> col;
for(int i = 1; i <= n; i++) {c[i] = read(); col.insert(c[i]);}
for(int i = 1; i <= n; i++) {
if(G[i].size() < col.size() - 1) continue;
memset(vis, 0, sizeof(vis));
vis[i] = 1;
if(check(i)) {
cout << "YES" << endl << i;
return 0;
}
}
cout << "NO" << endl;
return 0;
}

正解(解法2)

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define BUG(x) cout << #x << " = " << x << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto i:x) cout << i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 0.00000001
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second int n, u, v, lis[100005], cnt[100005], tot;
vector<int> adj[100005]; int main() {
ios::sync_with_stdio(false);
cin >> n;
REP (i, n - 1) {
cin >> u >> v;
adj[v].pb(u);
adj[u].pb(v);
}
FOR (i, 1, n) cin >> lis[i];
FOR (i, 1, n) {
for (int nex: adj[i]) if (lis[i] != lis[nex]) {
cnt[i]++;
cnt[nex]++;
tot++;
}
}
FOR (i, 1, n) if (cnt[i] == tot) {
cout << "YES" << endl << i;
return 0;
}
cout << "NO";
}

D

题意:

给出一些边长为odd的矩形,用最多四种颜色*给矩形染色,使得相邻颜色不同。

题解:

首先边长为odd,那么如果两个矩形相邻,那么他们左上顶点的奇偶性一定不同。

所以我们根据左上顶点的奇偶染色即可。

具体见代码。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 500011;
int n;
struct edge{
int sx,sy;
int xx,xy;
}a[MAXN];
inline int getint(){
int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
} inline void work(){
n=getint();
for(int i=1;i<=n;i++) {
a[i].xx=getint(); a[i].xy=getint();
a[i].sx=getint(); a[i].sy=getint();
a[i].xx=abs(a[i].xx); a[i].xy=abs(a[i].xy);
}
printf("YES\n");
for(int i=1;i<=n;i++) {
if(a[i].xx%2==1 && a[i].xy%2==1) printf("1");
else if(a[i].xx%2==1 && a[i].xy%2==0) printf("2");
else if(a[i].xx%2==0 && a[i].xy%2==1) printf("3");
else printf("4");
printf("\n");
}
} int main()
{
work();
return 0;
}

E

不会做。

Codeforces Round #395 Div.2 题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  3. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  4. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  5. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  6. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  7. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  8. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

  9. Codeforces Round #383 (Div. 2) 题解【ABCDE】

    Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...

随机推荐

  1. 学习python第十一天,函数3 函数的序列化和反序列化

    我们把变量从内存中变成可存储或传输的过程称之为序列化,序列化之后,就可以把序列化后的内容写入磁盘,或者通过网络传输到别的机器上. 反过来,把变量内容从序列化的对象重新读到内存里称之为反序列化,即unp ...

  2. Open source cryptocurrency exchange

    Peatio: https://github.com/peatio/peatio ViaBTC: https://github.com/viabtc/viabtc_exchange_server

  3. linux socketpair

    相对于无名管道来说,socketpair也是使用在亲缘进程之间,不过它提供了能够全双工通信的通道 man socketpair: #include <sys/types.h> /* See ...

  4. Android 文件管理器通用类 FileUtil

    1.整体分析 1.1.源代码如下,可以直接Copy. public class FileUtil { private FileUtil() { } //****系统文件目录************** ...

  5. Java文件 ---RandomAccessFile示例

    RandomAccessFile是用来访问那些保存数据记录的文件的,你就可以用seek( )方法来访问记录,并进行读写了.这些记录的大小不必相同:但是其大小和位置必须是可知的.但是该类仅限于操作文件 ...

  6. 1- js vue.js

    1 js 2  Vue.js

  7. HA集群中namenode连接不上journalnode,导致namenode启动不了

    查看日志发现一下的错误: 2018-10-08 15:29:26,373 FATAL org.apache.hadoop.hdfs.server.namenode.FSEditLog: Error: ...

  8. Java与Scala的两种简易版连接池

    Java版简易版连接池: import java.sql.Connection; import java.sql.DriverManager; import java.util.LinkedList; ...

  9. 使用wsimport命令生成webService客户端代码实例

    wsimport简介 在JDK的bin文件夹中,有一个wsimport.exe工具,可依据wsdl文件生成相应的类文件,将生存在本地这些类文件拷贝到需要使用的项目中,就可以像调用本地的类一样调用web ...

  10. wxPython 界面编程的有关事件

    在事件处理的过程中涉及四个要素: 1.事件. 它是用户对界面的操作,在wxPython中事件被封装成事件类wx.Event及其子类,例如按钮事件类wx.CommandEvent,鼠标事件类是wx.Mo ...