博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #421 (Div. 2)
阅读量:5892 次
发布时间:2019-06-19

本文共 4917 字,大约阅读时间需要 16 分钟。

Codeforces Round #421 (Div. 2)

Table of Contents Codeforces Round #421 (Div. 2)A. Mister B and Book ReadingB. Mister B and Angle in PolygonD. Mister B and PR Shifts

A. Mister B and Book Reading

Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.

At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second — v0 + a pages, at third — v0 + 2a pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than v1 pages per day.

Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time.

Help Mister B to calculate how many days he needed to finish the book.

Input

First and only line contains five space-separated integers: c, v0, v1, a and l (1 ≤ c ≤ 1000, 0 ≤ l < v0 ≤ v1 ≤ 1000, 0 ≤ a ≤ 1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.

Output

Print one integer — the number of days Mister B needed to finish the book.

题意:有一本书c页,每天看v0+i*a页,最多看v1页,每次返回l页,几天看完?

#include 
using namespace std;int main(){ int c,v0,v1,a,l; scanf("%d%d%d%d%d",&c,&v0,&v1,&a,&l); int ans = 0; while(true) { ans++; c-=v0; if(c<=0) break; v0+=a; if(v0>v1) v0=v1; c+=l; } printf("%d\n",ans); return 0;}

B. Mister B and Angle in Polygon

On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides).

That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices v1, v2, v3 such that the angle (where v2 is the vertex of the angle, and v1 and v3 lie on its sides) is as close as possible to a. In other words, the value should be minimum possible.

If there are many optimal solutions, Mister B should be satisfied with any of them.

Input

First and only line contains two space-separated integers n and a (3 ≤ n ≤ 105, 1 ≤ a ≤ 180) — the number of vertices in the polygon and the needed angle, in degrees.

Output

Print three space-separated integers: the vertices v1, v2, v3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order.

题意:正n边形,选三个点,组成的三角形最接近;

分析:求出最小角,180/n

#include 
using namespace std;int main(){ int n; double a; scanf("%d%lf",&n,&a); double k = 180.0/n; double ans = k; double minx = abs(a-ans); int flag = 2; for(int i=1;i
abs(a-ans)) { flag = i+2; minx = abs(a-ans); } } printf("%d %d %d\n",1,n,flag); return 0;}

D. Mister B and PR Shifts

Some time ago Mister B detected a strange signal from the space, which he started to study.

After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation which has the minimum possible deviation.

Let's define the deviation of a permutation p as .

Find a cyclic shift of permutation p with minimum possible deviation. If there are multiple solutions, print any of them.

Let's denote id k (0 ≤ k < n) of a cyclic shift of permutation p as the number of right shifts needed to reach this shift, for example:

  • k = 0: shift p1, p2, ... p**n,
  • k = 1: shift pn, p1, ... pn - 1,
  • ...,
  • k = n - 1: shift p2, p3, ... p**n, p1.

Input

First line contains single integer n (2 ≤ n ≤ 106) — the length of the permutation.

The second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the elements of the permutation. It is guaranteed that all elements are distinct.

Output

Print two integers: the minimum deviation of cyclic shifts of permutation p and the id of such shift. If there are multiple solutions, print any of them.

题意:循环队列n次,使得\sum_{i=1}^{n}|p[i]-i| 最小;

分析:和CSUFTOJ1021原理很类似;

记录下来cur移动k次,有多少个正数要变符号,这个cur是一个动态的,最后一个数移动到最前面会产生影响,最后一个数的移走,会对整体要L,R产生影响。

#include
#include
#define LL long longint p[1000005], cur[2000005];int main(void){ LL ans, sum; int n, L, r, i, temp; scanf("%d", &n); sum = L = r = temp = 0; for(i=1; i<=n; i++) scanf("%d", &p[i]); for(i=1; i<=n; i++) { sum += abs(p[i]-i); if(p[i]>=i) { L++; cur[p[i]-i]++; } else r++; } ans = sum; for(i=0; i

转载于:https://www.cnblogs.com/TreeDream/p/7107579.html

你可能感兴趣的文章
用Golang写一个搜索引擎(0x01)--- 基本概念
查看>>
【算法之美】logn 时间复杂度求解两个有序数组的中位数
查看>>
树的总结--树的性质(树的深度) leetcode
查看>>
docker环境搭建ELK
查看>>
webpack sourcemap 选项多种模式的一些解释
查看>>
document.createElement()的用法
查看>>
MySQL 数据库怎样把一个表的数据插入到另一个表
查看>>
HTTP协议及其POST与GET操作差异 & C#中如何使用POST、GET等
查看>>
nginx正则笔记
查看>>
delphi实现数字的倒计时
查看>>
在 IIS 下添加 FLV 类型文件的支持
查看>>
java线程学习3——线程的停止
查看>>
穿过任意防火墙NAT的远程控制软件TeamViewer
查看>>
PIX防火墙基本特性:失效处理机制和冗余-原理与实验
查看>>
域环境内部署Bginfo来统计用户计算机信息
查看>>
nagios短信报警(飞信fetion20080522004-linrh4)
查看>>
【Android游戏开发之六】在SurfaceView中添加组件!!!!并且相互交互数据!!!!...
查看>>
创建实体类使用Hibernate
查看>>
异常处理汇总-开发工具
查看>>
[LeetCode] Excel Sheet Column Number 求Excel表列序号
查看>>