Codeforces Round #421 (Div. 2)(A+B)

A. Mister B and Book Reading
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.

Examples
input
5 5 10 5 4
output
1
input
12 4 12 4 1
output
3
input
15 1 100 0 0
output
15
Note
In the first sample test the book contains 5 pages, so Mister B read it right at the first day.

In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.

In third sample test every day Mister B read 1 page of the book, so he finished in 15 days.
题意:一本书一共c页。初始速度每天看v0页,速度增长量为a。v1为限制的最大速度。后一天会复习看过的l页。问第一次看到最后一页的天数。
题解:模拟
代码:

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
typedef long long int ll;
typedef pair<int,int>pa;
const int N=1e5+10;
const int MOD=1e9+7;
const ll INF=1e18;
int read()
{
    int x=0;
    char ch = getchar();
    while('0'>ch||ch>'9')ch=getchar();
    while('0'<=ch&&ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return x;
}
/************************************************************/
int main()
{
    int c,v0,v1,a,l,i;
    cin>>c>>v0>>v1>>a>>l;
    int cnt=0;
    for(i=1;;i++)
    {
        if(i==1)
        {
            cnt+=v0;
            if(cnt>=c) break;
            v0+=a;
            if(v0>=v1)
            v0=v1;
        }
        else
        {
            cnt-=l;
            cnt+=v0;
            if(cnt>=c) break;
            v0+=a;
            if(v0>=v1)
            v0=v1;
        }
    }
    cout<<i<<endl;
}

B. Mister B and Angle in Polygon
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.

Examples
input
3 15
output
1 2 3
input
4 67
output
2 1 3
input
4 68
output
4 1 2
Note
In first sample test vertices of regular triangle can create only angle of 60 degrees, that’s why every possible angle is correct.

Vertices of square can create 45 or 90 degrees angles only. That’s why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: “3 1 2”, “3 2 4”, “4 2 3”, “4 3 1”, “1 3 4”, “1 4 2”, “2 4 1”, “4 1 3”, “3 1 4”, “3 4 2”, “2 4 3”, “2 3 1”, “1 3 2”, “1 2 4”, “4 2 1”.

In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: “2 1 4”, “3 2 1”, “1 2 3”, “4 3 2”, “2 3 4”, “1 4 3”, “3 4 1”.
题意:给你正n边形。让你找到正n边形中的一个角跟a的差的绝对值最小。输出这个角的下标。
题解:
正3三角形可以画出60°。
正4边形可以画出45°90°。
正5变形可以画出36° 72° 108°
正n变形可以画出180/n,180/n*2……180*(n-2)/n.
判断一下即可(注意用double)。
代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int>pa;
const int N=1e5+10;
const int MOD=1e9+7;
const ll INF=1e18;
int read()
{
    int x=0;
    char ch = getchar();
    while('0'>ch||ch>'9')ch=getchar();
    while('0'<=ch&&ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return x;
}
/************************************************************/
int main()
{
    double  n,m;
    cin>>n>>m;
    double  ans=(n-2)*180;
    double  cnt=ans/n;
    double tmp=cnt/(n-2);
    int nn=(int)n;
    if(m<=tmp)
    {
         printf("1 2 %d\n",nn);
    }
    else if(m>=cnt)
    {
         printf("1 2 3\n");
    }
    else
    {
        double i=m/tmp;
        int  v=(int)round(i);
        printf("1 2 %d\n",nn+1-v);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值