A、B略

C题 ——贪心,二分查找:

对于每一个a[i], 在d中二分查找 s-b[i],注意不要忘记计算速度为x时需要花费的最小时间,以及整数范围为64位整数

 1 #include <cstdio>
2 #include <algorithm>
3 #include <cstring>
4
5 using namespace std;
6 const int maxn = 2*100000+10;
7 typedef long long LL;
8
9 int n, m, k;
10 int x, s;
11 int a[maxn], b[maxn], c[maxn], d[maxn];
12
13 int main() {
14 scanf("%d%d%d", &n, &m, &k);
15 scanf("%d%d", &x, &s);
16 a[0] = x;
17 b[0] = 0;
18 for(int i = 1; i <= m; i++) scanf("%d",&a[i]);
19 for(int i = 1; i <= m; i++) scanf("%d",&b[i]);
20 for(int i = 0; i < k; i++) scanf("%d",&c[i]);
21 for(int i = 0; i < k; i++) scanf("%d",&d[i]);
22 LL ans = LL(n)*x;
23 for(int i = 0; i <= m; i++) {
24 if(b[i] <= s) {
25 int temp = b[i];
26 int tt = upper_bound(d, d+k, s - temp) - d;
27 if(tt) {
28 tt--;
29 LL as = n - c[tt] > 0 ? LL(n - c[tt]) * a[i] : 0;
30 ans = min(ans, as);
31 }
32 else {
33 LL as = LL(n) * a[i];
34 ans = min(ans, as);
35 }
36 }
37 }
38 printf("%I64d\n", ans);
39 }

D 思路很简单,注意细节即可

  1 #include <cstdio>
2 #include <vector>
3 #include <algorithm>
4 #include <cstring>
5 #include <cstdlib>
6 #include <cmath>
7 using namespace std;
8 const int maxn = 500000+10;
9
10 struct P{
11 char ch;
12 double dist;
13 P(char c, double d): ch(c), dist(d){}
14 bool operator < (const P& b)const {
15 return dist < b.dist;
16 }
17 };
18 vector<P> dig1, dig2, dig3, dig4;
19 vector<P> ver1, ver2, ver3, ver4;
20
21 int n;
22 int x0, y0_;
23 #define y0 y0_
24 void ins(char c, int dx, int dy) {
25 if(dx == dy) {
26 if(dx > 0) {
27 double dis = sqrt(double(dy)*dy + double(dx)*dx);
28 dig1.push_back(P(c, dis));
29 }
30 if(dx < 0) {
31 double dis = sqrt(double(dy)*dy + double(dx)*dx);
32 dig3.push_back(P(c, dis));
33
34 }
35 }
36 if(dx == -dy) {
37 if(dx > 0) {
38 double dis = sqrt(double(dy)*dy + double(dx)*dx);
39 dig4.push_back(P(c, dis));
40 }
41 if(dx < 0) {
42 double dis = sqrt(double(dy)*dy + double(dx)*dx);
43 dig2.push_back(P(c, dis));
44
45 }
46 }
47 if(dy == 0){
48 if(dx > 0) {
49 double dis = sqrt(double(dy)*dy + double(dx)*dx);
50 ver1.push_back(P(c,dis));
51 }
52 if(dx < 0) {
53 double dis = sqrt(double(dy)*dy + double(dx)*dx);
54 ver3.push_back(P(c,dis));
55
56 }
57 }
58 if(dx == 0){
59 if(dy > 0) {
60 double dis = sqrt(double(dy)*dy + double(dx)*dx);
61 ver2.push_back(P(c, dis));
62 }
63 if(dy < 0) {
64 double dis = sqrt(double(dy)*dy + double(dx)*dx);
65 ver4.push_back(P (c, dis));
66 }
67 }
68 }
69 int main () {
70 scanf("%d", &n);
71 scanf("%d%d", &x0, &y0);
72 for(int i = 0; i < n; i++) {
73 char ch;
74 int xx, yy;
75 getchar();
76 scanf("%c%d%d", &ch, &xx, &yy);
77 int dy = yy - y0, dx = xx - x0;
78 ins(ch , dx, dy);
79 }
80 sort(dig1.begin(), dig1.end());
81 sort(dig2.begin(), dig2.end());
82 sort(dig3.begin(), dig3.end());
83 sort(dig4.begin(), dig4.end());
84 sort(ver1.begin(), ver1.end());
85 sort(ver2.begin(), ver2.end());
86 sort(ver3.begin(), ver3.end());
87 sort(ver4.begin(), ver4.end());
88 if(dig1.size()) {
89 if(dig1[0].ch == 'Q' || dig1[0].ch == 'B') {
90 printf("YES\n");
91 return 0;
92 }
93 }
94 if(dig2.size()) {
95 if(dig2[0].ch == 'Q' || dig2[0].ch == 'B') {
96 printf("YES\n");
97 return 0;
98 }
99 }
100 if(dig3.size()) {
101 if(dig3[0].ch == 'Q' || dig3[0].ch == 'B') {
102 printf("YES\n");
103 return 0;
104 }
105 }
106 if(dig4.size()) {
107 if(dig4[0].ch == 'Q' || dig4[0].ch == 'B') {
108 printf("YES\n");
109 return 0;
110 }
111 }
112 if(ver1.size()) {
113 if(ver1[0].ch == 'Q' || ver1[0].ch == 'R') {
114 printf("YES\n");
115 return 0;
116 }
117 }
118
119 if(ver2.size()) {
120 if(ver2[0].ch == 'Q' || ver2[0].ch == 'R') {
121 printf("YES\n");
122 return 0;
123 }
124 }
125 if(ver3.size()) {
126 if(ver3[0].ch == 'Q' || ver3[0].ch == 'R') {
127 printf("YES\n");
128 return 0;
129 }
130 }
131 if(ver4.size()) {
132 if(ver4[0].ch == 'Q' || ver4[0].ch == 'R') {
133 printf("YES\n");
134 return 0;
135 }
136 }
137 printf("NO\n");
138 return 0;
139
140 }

E题:首先使用并查集将相同颜色的结点缩成一点,此时树中结点黑白相间,只需要求出树的直径(最长路)除以2就是答案。

 #include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std; const int maxn = +;
vector<int> G[maxn];
void add(int v, int u) {
G[v].push_back(u);
G[u].push_back(v);
}
int n;
int col[maxn];
int col2[maxn];
int vis[maxn];
int pa[maxn];
int findpa(int x) {return x == pa[x] ? x : pa[x] = findpa(pa[x]);}
int from, ans;
void dfs(int u, int v, int d) {
if(d > ans) {
ans = d;
from = v;
}
for(int i = ; i< G[v].size(); i++) {
int z = G[v][i];
if(z != u) {
dfs(v, z, d+);
}
}
}
int U[maxn];
int V[maxn];
int main() {
scanf("%d", &n);
for(int i = ; i <= n; i++)
scanf("%d", &col[i]); for(int i = ; i < n; i++)
scanf("%d%d", &U[i], &V[i]);
for(int i = ; i <= n; i++) pa[i] = i;
for(int i = ; i <= n; i++) {
int fu = findpa(U[i]);
int fv = findpa(V[i]);
if(col[fu] == col[fv]) {
pa[fu] = fv;
}
}
for(int i = ; i <= n; i++) {
int fu = findpa(U[i]);
int fv = findpa(V[i]);
if(col[fu] != col[fv]) {
add(fu, fv);
}
}
ans = -;
int u = pa[];
for(int i = ; i < G[u].size(); i++) {
int v = G[u][i];
dfs(u, v, );
}
u = from;
for(int i = ; i < G[u].size(); i++) {
int v = G[u][i];
dfs(u, v, );
}
ans = (ans+)/;
printf("%d\n", ans);
}

F题:注意到  a&b + a|b = a+b

即可根据数组b, c的定义求出a,然后用求出的a反推数组b,c判断是否是解

详见代码:

 #include <iostream>
#include <algorithm>
#include <cstring> using namespace std;
const int maxn = + ;
typedef long long LL; LL a[maxn], b[maxn], c[maxn];
int num[];
int n;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for(int i = ; i < n; i++) cin >> b[i];
for(int i = ; i < n; i++) cin >> c[i];
LL sum = ;
for(int i = ; i < n; i++) {
a[i] = b[i] + c[i];
sum += a[i];
}
if(sum % (*n)) {
cout << - << endl;
return ;
}
sum /= *n;
for(int i = ; i < n; i++) {
a[i] = (a[i] - sum);
if(a[i] % n) {
cout << - << endl;
return ;
}
else{
a[i] /= n;
}
}
for(int i = ; i < n; i++) {
LL temp = a[i];
for(int j = ; j < ; j++) {
num[j] += temp%;
temp /= ;
}
}
for(int i = ; i < n; i++) {
LL b_ = , c_ = ;
for(int j = ; j < ; j++) {
if(a[i] & (1LL << j)) {
b_ += num[j] * (1LL << j);
c_ += n * (1LL << j);
}
else c_ += num[j] * (1LL << j);
}
if(b_ != b[i] || c_ != c[i]) {
cout << - << endl;
return ;
}
}
cout << a[];
for(int i = ; i < n; i++) {
cout << " " << a[i];
}
cout << endl;
return ;
}

codeforce 379(div.2)的更多相关文章

  1. Codeforces Round #370 - #379 (Div. 2)

    题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi  ...

  2. Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black

    A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...

  3. Codeforces Round #379 (Div. 2)

    A ~~ B ~~ C 对于第二种方法,我们可以任取一个换c[i]个potions,花费d[i]:或者是不取,我的做法就是枚举这些情况,得到剩余的s,再尽量优的获取小的a[i]: 枚举+二分 #inc ...

  4. Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟

    A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Codeforces Round #379 (Div. 2) F. Anton and School

    题意: 给你n对 b[i], c[i], 让你求a[i],不存在输出-1 b[i] = (a[i] and a[1]) + (a[i] and a[2]) + (a[i] and a[3]) +... ...

  6. Codeforces Round #379 (Div. 2) E. Anton and Tree

    题意: 给一颗树 每个节点有黑白2色 可以使一个色块同事变色,问最少的变色次数. 思路: 先缩点 把一样颜色的相邻点 缩成一个 然后新的树 刚好每一层是一个颜色. 最后的答案就是树的直径/2 不过我用 ...

  7. Codeforces Round #379 (Div. 2) 解题报告

    题目地址 本次CF是在今天早上深夜进行,上午有课就没有直接参加.今天早上上课坐到后排参加了virtual participation.这次CF前面的题目都非常的水,不到10分钟就轻松过了前两题,比较郁 ...

  8. Codeforces Round #379 (Div. 2) 总结分享

    前言 初入acm的新手,打算在cf混.这几天没有比赛,就做了个最新的Virtual participation.虽然说div2比较简单,但还是被虐得体无完肤...Orz.两个小时,共6道题.最后只AC ...

  9. Codeforces Round #379 (Div. 2) E. Anton and Tree 缩点 直径

    E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a t ...

随机推荐

  1. 第三方数据库管理工具Navicat使用教程

    一.Navicat Premium是一个功能强大的第三方数据库管理工具,可以连接管理MySQL.Oracle.PostgreSQL.SQLite 及 SQL Server数据库. 使用Navicat软 ...

  2. bnd -buildpath指令的用法

    -buildpath的作用是为项目添加运行时依赖.这个依赖可以是workspace中的另一个项目或者是仓库中的另一个bundle. -buildpath指令只会在编译和构建时起作用,它从来不会被用来运 ...

  3. ChaosBlade 发布对 C++ 应用混沌实验的支持

    前言 为满足 C++ 应用系统故障演练,阿里妈妈安全生产团队开源了 C++ 混沌实验执行器,填补了 C++ 应用混沌工程实验的空白,其遵循<混沌实验模型>,可通过 ChaosBlade 工 ...

  4. 【Django入坑之路】Django后台上传图片,以及前端的显示

    #setting配置: MEDIA_URL = "/media/" MEDIA_ROOT = os.path.join(BASE_DIR, "media") # ...

  5. NodeJS基础之Express路由和中间件

    路由 路由是指如何定义应用的端点(URIs)以及如何响应客户端的请求. 路由是由一个 URI.HTTP 请求(GET.POST等)和若干个句柄组成,它的结构如下: app.method(path, [ ...

  6. 2018-9-2-WPF-开发自动开机启动程序

    title author date CreateTime categories WPF 开发自动开机启动程序 lindexi 2018-09-02 15:10:52 +0800 2018-9-2 14 ...

  7. Linux常用命令1 文件处理命令

    1.命令格式 1.用中括号括起来的内容都不是必填内容,碧如上图的选项和参数,有些命令不写选项和参数也可以执行 2.注意图中的简化选项与完整选项说明,完整选项要两个横杆-- 2.目录处理命令ls 1.文 ...

  8. javaweb学习总结(一) - - JSP取得绝对路径

    在JavaWeb开发中,常使用绝对路径的方式来引入JavaScript和CSS文件,这样可以避免因为目录变动导致引入文件找不到的情况,常用的做法如下: 例如: 1 <!--使用绝对路径的方式引入 ...

  9. 从零学React Native之12 组件的生命周期

    一个React Native组件从它被加载,到最终被卸载会经历一个完整的生命周期.所谓生命周期,就是一个对象从开始生成到最后消亡所经历的状态,理解生命周期,是合理开发的关键. ES6语法和之前的ES5 ...

  10. 洛谷2387 BZOJ3669魔法森林题解

    题目链接 BZ链接 这道题被很多人用spfa水了过去,表示很... 其实spfa很好卡,这组数据可以卡掉大多数spfa 链接:密码:rjvk 这里讲一下LCT的做法 我们按照a将边排序,然后依次添加 ...