闲来无事一套CF啊,我觉得这几个题还是有套路的,但是很明显,这个题并不难

A. Pineapple Incident
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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 tt + st + s + 1, t + 2st + 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.

Input

The first and only line of input contains three integers ts 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.

Output

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.

Examples
input
3 10 4
output
NO
input
3 10 3
output
YES
input
3 8 51
output
YES
input
3 8 52
output
YES
Note

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 ;
}
B. Barnicle
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The first and only line of input contains a single string of form a.deb where ad 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.

Output

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).

Examples
input
8.549e2
output
854.9
input
8.549e3
output
8549
input
0.33e0
output
0.33
 B就是把一个科学计数法转换为数字,但是这个数可能特别大,LL是存不在的,所以想存位数就好了。而且这个只要一部分,还有情况是你要补0
#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 ;
}
C. Lorenzo Von Matterhorn
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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 vu 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).

Input

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.

Output

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.

Example
input
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
output
94
0
32
Note

In the example testcase:

Here are the intersections used:

  1. Intersections on the path are 3, 1, 2 and 4.
  2. Intersections on the path are 4, 2 and 1.
  3. Intersections on the path are only 3 and 6.
  4. 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.
  5. Intersections on the path are 6, 3 and 1.
  6. Intersections on the path are 3 and 7. Passing fee of the road between them is 0.
  7. 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)的更多相关文章

  1. Codeforces Round #362 (Div. 2) C. Lorenzo Von Matterhorn (类似LCA)

    题目链接:http://codeforces.com/problemset/problem/697/D 给你一个有规则的二叉树,大概有1e18个点. 有两种操作:1操作是将u到v上的路径加上w,2操作 ...

  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 ...

  3. 【转载】【树形DP】【数学期望】Codeforces Round #362 (Div. 2) D.Puzzles

    期望计算的套路: 1.定义:算出所有测试值的和,除以测试次数. 2.定义:算出所有值出现的概率与其乘积之和. 3.用前一步的期望,加上两者的期望距离,递推出来. 题意: 一个树,dfs遍历子树的顺序是 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #362 (Div. 2) B 模拟

    B. Barnicle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  8. Codeforces Round #362 (Div. 2) A 水也挂

    A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. 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 ...

随机推荐

  1. java定时读取文件

    在项目中经常会用到定时器,在笔试或者面试中也会经常问到定时器和IO流. public class TimerDemo { public static void main(String[] args) ...

  2. MyBatis框架的XML数据访问Dao层接口的组合使用

    MyBatis 的前生为Apache的开源项目iBatis.其优势在于灵活,几乎可以替代JDBC,同时提供了编程接口.目前MyBatis的数据访问Dao层不需要实现类,也不需要像JDBC那样拼接Hql ...

  3. ABC时间管理法

    名称 ABC时间管理法 属于 事务优先顺序法的“鼻祖” 做法 将待办的事项按照又重要到轻的顺序划分为A,B,C三个等级,然后按照事项的重要等级依据完成任务的做事方法. 特点 使学习.工作和生活等活动在 ...

  4. 使用vscode软件运行zebrajs框架小结

    最近在研究使用zebrajs框架,用vscode编辑器进行开发.vsc这个编辑器说起来还是很强大的,就是支持各种系统的多种语言开发.用于前端的话可以直接在编辑器上边调试javascript,就是需要n ...

  5. Android Studio你必须学会的快捷键(Eclipse转AS必看)

    前言:从Eclipse转到Android Studio之后,一开始把keymap设置成Eclipse,却发现有些常用的快捷键都失效了,大概是冲突了.想了下,觉得与其重新设置快捷键,不如去适应AS的快捷 ...

  6. IOS之constraints

    anyway, you can do this with auto layout. You can do it entirely in IB as of Xcode 5.1. Let's start ...

  7. COGS 264. 数列操作

    时间限制:1 s   内存限制:160 MB [问题描述] 假设有一列数 {Ai }(1 ≤ i ≤ n) ,支持如下两种操作: (1)将 A k 的值加 D .( k, D 是输入的数) (2) 输 ...

  8. VMware网络适配器设置

    VMware网络连接主要有三种方式,分别是桥接,NAT和Host-only. 桥接:直接使用的是真实机的物理网卡(有线网卡,无线网卡),会占用局域网中的一个IP,因此在设置虚拟机IP时要避免与同网段的 ...

  9. Cordova插件中JavaScript代码与Java的交互细节介绍

    在Cordova官网中有这么一张架构图:大家看右下角蓝色的矩形框"Custom Plugin"--自定义插件.意思就是如果您用Cordova打包Mobile应用时,发现您的移动应用 ...

  10. Python学习日志_2017/09/09

    今天早晨学习<Head First HTML and CSS>.随着内容逐渐深入,知识量逐渐增加,今天早晨三个小时学习了一章:<Html的基本元素>,学到了不少的东西.比如,什 ...