Codeforces Round #362 (Div. 2)
闲来无事一套CF啊,我觉得这几个题还是有套路的,但是很明显,这个题并不难
1 second
256 megabytes
standard input
standard output
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t + s, t + s + 1, t + 2s, t + 2s + 1, etc.

Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time x (in seconds), so he asked you to tell him if it's gonna bark at that time.
The first and only line of input contains three integers t, s and x (0 ≤ t, x ≤ 109, 2 ≤ s ≤ 109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.
Print a single "YES" (without quotes) if the pineapple will bark at time x or a single "NO" (without quotes) otherwise in the only line of output.
3 10 4
NO
3 10 3
YES
3 8 51
YES
3 8 52
YES
In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52.
就是检查下x在不在这个数列,数列眉两项之间增加s,有的相邻两项差值是1
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,s,x;
cin>>t>>s>>x;
if(x<t+s){puts(x==t?"YES":"NO");return ;}
int k=(x-t)/s;
if(t+k*s==x||t+k*s+==x)puts("YES");else puts("NO");
return ;
}
1 second
256 megabytes
standard input
standard output
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.

Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x = A × 10B is true. In our case A is between 0 and 9 and B is non-negative.
Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.
The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character 'e' (0 ≤ a ≤ 9, 0 ≤ d < 10100, 0 ≤ b ≤ 100) — the scientific notation of the desired distance value.
a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.
Print the only real number x (the desired distance value) in the only line in its decimal notation.
Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.
Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).
8.549e2
854.9
8.549e3
8549
0.33e0
0.33
#include<bits/stdc++.h>
using namespace std;
char a[];
int main() {
int ex=;
scanf("%c.%[0-9]e%d",&a[],a+,&ex);
int f=;
for(int i=; a[i]; i++) {
if(a[i]!='') {
f=;
}
}
if(!f&&!ex)
printf("%c",a[]);
else {
for(int i=; i<ex+||a[i]; i++) {
if(i==ex+) printf(".");
printf("%c",!a[i]?'':a[i]);
}
}
return ;
}
1 second
256 megabytes
standard input
standard output
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two intersections.

Initially anyone can pass any road for free. But since SlapsGiving is ahead of us, there will q consecutive events happen soon. There are two types of events:
1. Government makes a new rule. A rule can be denoted by integers v, u and w. As the result of this action, the passing fee of all roads on the shortest path from u to v increases by w dollars.
2. Barney starts moving from some intersection v and goes to intersection u where there's a girl he wants to cuddle (using his fake name Lorenzo Von Matterhorn). He always uses the shortest path (visiting minimum number of intersections or roads) between two intersections.
Government needs your calculations. For each time Barney goes to cuddle a girl, you need to tell the government how much money he should pay (sum of passing fee of all roads he passes).
The first line of input contains a single integer q (1 ≤ q ≤ 1 000).
The next q lines contain the information about the events in chronological order. Each event is described in form 1 v u w if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest path from u to v by w dollars, or in form 2v u if it's an event when Barnie goes to cuddle from the intersection v to the intersection u.
1 ≤ v, u ≤ 1018, v ≠ u, 1 ≤ w ≤ 109 states for every description line.
For each event of second type print the sum of passing fee of all roads Barney passes in this event, in one line. Print the answers in chronological order of corresponding events.
7
1 3 4 30
1 4 1 2
1 3 6 8
2 4 3
1 6 1 40
2 3 7
2 2 4
94
0
32
In the example testcase:
Here are the intersections used:
- Intersections on the path are 3, 1, 2 and 4.
- Intersections on the path are 4, 2 and 1.
- Intersections on the path are only 3 and 6.
- Intersections on the path are 4, 2, 1 and 3. Passing fee of roads on the path are 32, 32 and 30 in order. So answer equals to 32 + 32 + 30 = 94.
- Intersections on the path are 6, 3 and 1.
- Intersections on the path are 3 and 7. Passing fee of the road between them is 0.
- Intersections on the path are 2 and 4. Passing fee of the road between them is 32 (increased by 30 in the first event and by 2 in the second).
Do what problem wants from you. The only thing is to find the path between the two vertices (or LCA) in the tree. You can do this in
since the height of the tree is
. You can keep edge weights in a map and get/set the value whenever you want. Here's a code for LCA:
LCA(v, u):
while v != u:
if depth[v] < depth[u]:
swap(v, u)
v = v/2 // v/2 is parent of vertex v

Time Complexity: 
这个C就是有个树,让你统计下这个树的LCA的边值
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll>road;
int main() {
ll q,rule,u,v,w,ans;
cin>>q;
while(q--) {
cin>>rule;
if(rule==) {
cin>>u>>v>>w;
while(u!=v) {
if(u<v)
swap(u,v);
road[u]+= w;
u /= ;
}
} else {
cin>>u>>v;
ans = ;
while(u!=v) {
if(u<v)
swap(u,v);
ans += road[u];
u /= ;
}
cout << ans << endl;
}
}
return ;
}
Codeforces Round #362 (Div. 2)的更多相关文章
- Codeforces Round #362 (Div. 2) C. Lorenzo Von Matterhorn (类似LCA)
题目链接:http://codeforces.com/problemset/problem/697/D 给你一个有规则的二叉树,大概有1e18个点. 有两种操作:1操作是将u到v上的路径加上w,2操作 ...
- #map+LCA# Codeforces Round #362 (Div. 2)-C. Lorenzo Von Matterhorn
2018-03-16 http://codeforces.com/problemset/problem/697/C C. Lorenzo Von Matterhorn time limit per t ...
- 【转载】【树形DP】【数学期望】Codeforces Round #362 (Div. 2) D.Puzzles
期望计算的套路: 1.定义:算出所有测试值的和,除以测试次数. 2.定义:算出所有值出现的概率与其乘积之和. 3.用前一步的期望,加上两者的期望距离,递推出来. 题意: 一个树,dfs遍历子树的顺序是 ...
- Codeforces Round #362 (Div. 2) A.B.C
A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #362 (Div. 2)->B. Barnicle
B. Barnicle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #362 (Div. 2)->A. Pineapple Incident
A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #362 (Div. 2) B 模拟
B. Barnicle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #362 (Div. 2) A 水也挂
A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #362 (Div. 2) D. Puzzles
D. Puzzles time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
随机推荐
- java 利用c3p0管理数据库连接池
数据库连接池类,用于获取数据库连接.利用单例模式保证所有的连接都只通过一个连接池管理. package com.mousewheel.dbcon; import java.io.InputStream ...
- ES-Mac OS环境搭建-kibana
简介 Kibana是一个为ElasticSearch 提供的数据分析的 Web 接口.可使用它对日志进行高效的搜索.可视化.分析等各种操作. 下载 打开elasticseach官网,单击downloa ...
- nodejs中的异步回调机制
1.再次clear Timer定时器的作用 setTimeOut绝非是传统意义上的“sleep”功能,它做不到让主线程“熄火”指定时间,它是用来指定:某个回调在固定时间后插入执行栈!(实际执行时间略长 ...
- 慢慢积累遇到的linux指令
sudo 用来以其他身份来执行命令,预设身份为root sudo apt install git 下载git sudo root 进入root身份(只有这个身份ubuntu和window系统之间才能共 ...
- JQ中的问题
$(function(){$(document).bind("click", function (e) {$(e.target).closest("p").cs ...
- 推荐一个免费的生成词云(word cloud)的在线工具
"词云"这个概念由美国西北大学新闻学副教授.新媒体专业主任里奇·戈登(Rich Gordon)提出. "词云"就是对网络文本中出现频率较高的"关键词& ...
- Python学习日志9月13日
昨天的学习日志没有写,乱忙了一整天,政治电脑. 好奇心重,想要给电脑装上传说中LInux操作系统,各种小问题折腾到半夜,今天又折腾到晚上才真正的装上系统. 可是装上系统后又发现各种的不好用.虽然界面比 ...
- iview 验证 trigger: 'blur,change', 同时加两个,省的每次还想input 还是 select
iview 验证 trigger: 'blur,change', 同时加两个,省的每次还想input 还是 select dataRuleValidate: { name: [{ required: ...
- 参考别人的代码写的aes加密,记录一下(AES,ECB模式,填充PKCS5Padding,数据块128位,偏移量无,以hex16进制输出)
package org.jimmy.autosearch2019.test; import java.security.SecureRandom; import javax.crypto.Cipher ...
- spring-security中的csrf防御机制(跨域请求伪造)
什么是csrf? csrf又称跨域请求伪造,攻击方通过伪造用户请求访问受信任站点.CSRF这种攻击方式在2000年已经被国外的安全人员提出,但在国内,直到06年才开始被关注,08年,国内外的多个大型社 ...