codeforces 592B/C
题目链接:http://codeforces.com/contest/592/problem/B
1 second
256 megabytes
standard input
standard output
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.
Ari draws a regular convex polygon on the floor and numbers it's vertices 1, 2, ..., n in clockwise order. Then starting from the vertex 1she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2, 3, ..., n (in this particular order). And then she puts a walnut in each region inside the polygon.

Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner.
Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?
The first and only line of the input contains a single integer n (3 ≤ n ≤ 54321) - the number of vertices of the regular polygon drawn by Ari.
Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.
5
9
3
1
One of the possible solutions for the first sample is shown on the picture above.
找规律。
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
cout<<(n-)*(n-)<<endl;
}
─────────────────────────────────────────────────────────────────────────────────────────────
题目链接:http://codeforces.com/contest/592/problem/C
1 second
256 megabytes
standard input
standard output
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of Lmeters today.

Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?
The first line of the input contains three integers t, w and b (1 ≤ t, w, b ≤ 5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
Print the answer to the problem as an irreducible fraction
. Follow the format of the samples output.
The fraction
(p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both pand q are divisible by d.
10 3 2
3/10
7 1 2
3/7
In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.
题意:
两个人跑步比赛,一个人一步只能走w米,一个人一步只能走b米;
终点位置可以在整数1~t里面随便选择一个;
终点之后都是陷阱,两个人比赛但两个人都不想死,所以不能越过终点,在这种情况下,谁走的远,就算谁赢;
然后问你选择平局的概率是多少。
题解:
算算样例,可以看出所有最小公倍数情况的终点都能产生平局;
我们设tail=min(w,b)-1,可以看出,1~tail位置的终点也产生平局,每个最小公倍数终点后面tail个位置也能产生平局;
那么我们就围绕这个进行计算,可以按照1~t里有多少个lcm(w,b)整数倍终点进行分类考虑;
不过有一个错误点就是lcm(w,b)超过unsigned long long范围的情况,
这样一来,因为t的范围限制,lcm(w,b)必然大于t了,只需要在前面特判一下lcm(w,b)>t的情况即可,
具体怎么特判,lcm(w,b) = (w*b) / gcd(w,b) > t,两边取对数进行比较即可。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long llu;
inline llu gcd(llu m,llu n){return n?gcd(n,m%n):m;}
llu lcm(llu m,llu n){return m/gcd(m,n)*n;}
void output(llu p,llu q)
{
llu pq_gcd=gcd(p,q);
cout<<p/pq_gcd<<"/"<<q/pq_gcd<<endl;
}
bool check(llu t,llu w,llu b)
{
return log(w*1.0)+log(b*1.0)-log(gcd(w,b)*1.0)>log(t*1.0);
}
int main()
{
llu t,w,b;
cin>>t>>w>>b; llu tail=min(w,b)-;//tail>=0 if(check(t,w,b))//判断lcm(w,b)>t?
{
output(min(tail,t),t);
return ;
} llu wb_lcm=lcm(w,b);
llu cnt=t/wb_lcm;
if(cnt==)
{
if(t<=tail)
{
cout<<"1/1"<<endl;
return ;
}
else
{
output(tail,t);
return ;
}
}
else if(cnt==)
{
llu ed=min(t%wb_lcm,tail)+;
output(tail+ed,t);
return ;
}
else
{
llu ed=min(t%wb_lcm,tail)+;
output(tail+(cnt-)*(tail+)+ed,t);
return ;
}
}
codeforces 592B/C的更多相关文章
- CodeForces 592B
题目链接: http://codeforces.com/problemset/problem/592/B 这个题目没啥说的,画图找规律吧,哈哈哈 程序代码: #include <cstdio&g ...
- codeforces 592B The Monster and the Squirrel
题目链接:http://codeforces.com/contest/592/problem/B 题目分类:数学,找规律 题目分析:重要的是画图找规律 代码: #include<bits/s ...
- Codeforces Round #328(Div2)
CodeForces 592A 题意:在8*8棋盘里,有黑白棋,F1选手(W棋往上-->最后至目标点:第1行)先走,F2选手(B棋往下-->最后至目标点:第8行)其次.棋子数不一定相等,F ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- OpenSift源代码编译过程记录
本文记录了在CentOS6.5上编译Sift的开源实现OpenSift的编译过程,同一时候记录了编译过程中的几个问题. sift的理论已经有非常多了,以下会给出链接: 1.Requirements a ...
- SPREAD for Windows Forms 下箭头追加行
''' <summary> ''' 下矢印の動作クラス ''' </summary> ''' <remarks></remarks> Public Cl ...
- ios开发之--UITableView中的visibleCells的用法
先上图: 具体代码如下: #import "ViewController.h" @interface ViewController ()<UITableViewDelegat ...
- [Python] 正确复制列表的方法
new = old[:] Python老鸟都知道以上代码是什么意思.它复制列表old到new.它对于新手来说是种困惑而且应该避免使用这种方法.不幸的是[:]标记法被广泛使用,可能是Python程序员不 ...
- Mac终端解压命令集合
tar 解包:tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) ——————————————— .gz 解压1 ...
- ScaleType属性
FIT_CENTER 把原图按照比例放大缩小到ImageView的高度,显示在ImageView的center(中部/居中显示). 1 2 CENTER_CROP 会拉伸图片以原图填满ImageV ...
- 【cs229-Lecture4】Newton’s method
之前我们在求Logistic回归时,用的是梯度上升算法,也就是要使得似然函数最大化,利用梯度上升算法,不断的迭代.这节课引出牛顿方法,它的作用和梯度上升算法的一样的,不同的是牛顿方法所需的迭代次数更少 ...
- 【前端积累】javascript事件
什么是事件? 事件是一种异步编程的实现方式,本质上是程序各个组成部分之间的通信.就是文档或浏览器窗口发生的一些特定的交互瞬间(某种动作). 1.事件流 事件流描述的是从页面中接收事件的顺序. 1)事件 ...
- 求组合数 C++程序
一 递归求组合数 设函数为void comb(int m,int k)为找出从自然数1.2.... .m中任取k个数的所有组合. 分析:当组合的第一个数字选定时,其后的数字是从余下的m-1个数中 ...
- Excel中countif函数的使用方法
1.countif函数的含义 在指定区域中按指定条件对单元格进行计数(单条件计数) 建议和countifs函数结合起来学习,可以观看小编的经验Excel中countifs函数的使用方法. END 2. ...