2017年9月24日训练总结

这次总结是9月22日到9月24日。

总体来说并不太好。这三天本来是要把hash看完,但是我太天真了,到现在只会一个简单hash的模板,稍微复杂一点就不会。字符串hash更别说。。。已经放弃,不能在这里浪费太多时间了。周六北京赛区的比赛,状态不是很好。个人一道题没做出来,小伙伴A了两道题。所有题目题意都能读懂,但是很显然都不会。最奇怪的是清华的dalao两个小时AK,然后再往下,第一页结束就是4道题了。可见清华的学生都对这些基本问题非常熟悉,而剩下的大部分都是读懂了却不会。我全程看了两道题,一道看完想出思路交给了队友敲代码,而另一道题明明知道是规律题却死活推不出公式。就是这道题:

题目7 : Bounce

时间限制: 1000ms
单点时限: 1000ms
内存限制: 256MB

描述

For Argo, it is very interesting watching a circle bouncing in a rectangle.

As shown in the figure below, the rectangle is divided into N×M grids, and the circle fits exactly one grid.

The bouncing rule is simple:

1. The circle always starts from the left upper corner and moves towards lower right.

2. If the circle touches any edge of the rectangle, it will bounce.

3. If the circle reaches any corner of the rectangle after starting, it will stop there.


Argo wants to know how many grids the circle will go through only once until it first reaches another corner. Can you help him?

输入

The input consists of multiple test cases. (Up to 105)

For each test case:

One line contains two integers N and M, indicating the number of rows and columns of the rectangle. (2 ≤ N, M ≤ 109)

输出

For each test case, output one line containing one integer, the number of grids that the circle will go through exactly once until it stops (the starting grid and the ending grid also count).

样例输入
2 2
2 3
3 4
3 5
4 5
4 6
4 7
5 6
5 7
9 15
样例输出
2
3
5
5
7
8
7
9
11
39
显然是规律题,但是经过多次枚举发现并没有什么规律,最后才知道原来要用到最大公约数。。。我还是太年轻了啊。。。

公式是( gcd(m,n)-1)*m*n+m+n //(m、n都除去最大公约数)

题解代码如下:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    return b == 0?a:gcd(b,a%b);
}
int main()
{
    ll n,m;
    while(~scanf("%lld%lld",&n,&m))
    {
        --n;--m;
        ll g = gcd(n,m);
        n /= g;m /= g;
        if(n == 1 && m == 1)
        {
            printf("%lld\n",g+1);
            continue;
        }
        ll sum=(g-1)*n*m+(n+m);
        printf("%lld\n",sum);
    }
    return 0;
}

另外,今天在南宁赛区的网络赛由于我们三个都有事,就没参加。我看了下A的人数最多的两道题,发现都是树状数组的问题,一个一维,一个二维。加上之前的比赛,几乎每场都有树状数组、线段树的题目,而且都不是太难。因此,为了不影响计划的进度,明天开始进攻线段树和树状数组。因为之前已经看过,这次就是强化记忆和熟练运用了。目标是在国庆节结束前把树状数组和线段树都熟练掌握并熟练运用,把资料都理解透彻,每类问题怎样处理都总结出来,还有基本的题型必须全部掌握。这一块儿是重点,一定要认真对待。

这个周也算勉勉强强完成了目标。hash有待以后的进一步巩固提高强化。今晚开始,再从树状数组开始,一定要彻底解决。

知道自己菜就要加倍努力,而且三分热度是毫无意义的,只有坚持下去,多思考,透彻理解,终究会找到往上拐的拐点。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值