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. PLAY2.6-SCALA(十二) 表单的处理

    一.表单处理流程如下 1.定义一个表单,在这里表单最多有22个字段 import play.api.data._ import play.api.data.Forms._ //要使用验证和约束 imp ...

  2. 第一份Markdown。。。。。菜鸟给跪了

    #First Markdown ##Hello World ###Ahaha - Python - Ruby - C++ - Haskell - C - Java 1. C 2. C++ 3. C# ...

  3. Polyfill简介

    1.什么是Polyfill? Polyfill是一个js库,主要抚平不同浏览器之间对js实现的差异.比如,html5的storage(session,local), 不同浏览器,不同版本,有些支持,有 ...

  4. Nginx设置静态页面压缩和缓存过期时间的方法 (转)

    使用nginx服务器的朋友可能都知道需要设置html静态页面缓存与页面压缩与过期时间的设置了,下面我来给各位同学介绍一下配置方法,包括对ico,gif,bmp,jpg,jpeg,swf,js,css, ...

  5. quarts之Cron表达式示例

    cron表达式含义及范例如下: 字段名                 允许的值                        允许的特殊字符 秒                         0- ...

  6. objectarx之遍历当前模型空间中的所有实体,并对每个实体进行炸开

    //炸开void BomEntity(){ AcDbBlockTable *pBlkTbl; acdbHostApplicationServices()->workingDatabase()-& ...

  7. 【风马一族_php】NO4_php基础知识

    原文来自:http://www.cnblogs.com/sows/p/6017018.html(博客园的)风马一族 侵犯版本,后果自负 回顾 运算符:算术运算符.逻辑运算符.比较运算符.位运算符.赋值 ...

  8. MaxCompute问答整理之6月

    本文是基于本人对MaxCompute产品的学习进度,再结合开发者社区里面的一些问题,进而整理成文.希望对大家有所帮助,下面咱们正式开始. 1.什么是MaxCompute呢?MaxCompute是由阿里 ...

  9. 【Leetcode链表】旋转链表(61)

    题目 给定一个链表,旋转链表,将链表每个节点向右移动 k 个位置,其中 k 是非负数. 示例 1: 输入: 1->2->3->4->5->NULL, k = 2 输出: ...

  10. MacOS局域网访问Windows7共享文件

    配置步骤 Windows7 进入[控制面板]-[网络和共享中心]-[高级共享设置] 启用网络发现 启用文件和打印机共享 选择要共享的文件或文件夹,点击[共享]-[特定用户] 选择Windows7当前登 ...