A. Playing with Paper

这是Codeforces Round #296 (Div. 2)A题,题意就是:

小明有一张长为a,宽为b的纸,每当要折纸鹤时,就从纸上剪下一个正方形,然后,剩下的纸还可以剪出正方形,要是剩下的纸刚好是正方形的话,就直接拿这个正方形去做最后一个纸鹤,求总共可以折多少个纸鹤。小明是个节约资源的好孩子。

_______________

input

2 1

output

2

_______________

input

10 7

output

6

_______________

输入的2个数字分别是长和宽,输出总共可以折叠的纸鹤数。两种输入的情况如下:

problem tag 刚好是math,是不是很熟悉,这个东西,有点像gcd,应该就是辗转相除法了,好,上代码。

#include <iostream>
using namespace std;
long long solve(long long a, long long b){
    long long cnt = 0;
    while(b){
	    long long e = a/b, d = a%b;
	    cnt += e;
	    a = b; b = d;
    }
    return cnt;
}
int main(){
    long long a, b;
    cin >> a >> b;
    cout << solve(a, b);
    return 0;
}
时间: 2024-12-19 02:36:46

A. Playing with Paper的相关文章

Codeforces Round #296 (Div. 2) A. Playing with Paper

A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm ?×? b mm sheet of paper (a?>?b). Usually the first step in making an origami is making a square piece of paper from the

Codeforces Round #296 (Div. 2)——A long long——Playing with Paper

One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm  ×  b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by

A - Playing with Paper (CodeForces - 527A)

- 题目大意 给定的矩形,每次裁剪最大的正方形,直到最后剩下正方形,总共有多少个正方形. - 解题思路 显然,每次裁剪后,原来的宽和(长-宽)变成了现在的长和宽,直到长等于宽. - 代码 #include<iostream> using namespace std; long long num(long long a, long long b) { if (b == 1) return a; if (a % b == 0) return a / b; return num(b, a % b)

CodeForces 327D Block Tower(DFS)

题意  给你一个城市的地图  你可以在地图上的 . 上建房子#上不能建房子  红房子可以装200个人  蓝房子可以装100个人  只有相邻位置有蓝房子时才能建红房子  你也可以拆掉已经建成的房子  拆掉后该点又变成  . 这题想到了就很容易了  因为没有限制要步数最少  可以先把左右的地方都建成蓝房子  然后就变成求连通块的题了  每个蓝房子连通块内依次拆掉建红房子  最终就只剩下一个蓝房子了 #include <bits/stdc++.h> using namespace std; cons

Codeforces Round #296 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/527 A. Playing with Paper time limit per test:2 seconds memory limit per test:256 megabytes One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm ?×? b mm sheet

CF327D (dfs)

After too much playing on paper, Iahub has switched to computer games. The game he plays is called "Block Towers". It is played in a rectangular grid with n rows and m columns (it contains n?×?m cells). The goal of the game is to build your own

Paper Reading 1 - Playing Atari with Deep Reinforcement Learning

来源:NIPS 2013 作者:DeepMind 理解基础: 增强学习基本知识 深度学习 特别是卷积神经网络的基本知识 创新点:第一个将深度学习模型与增强学习结合在一起从而成功地直接从高维的输入学习控制策略 详细是将卷积神经网络和Q Learning结合在一起.卷积神经网络的输入是原始图像数据(作为状态)输出则为每一个动作相应的价值Value Function来预计未来的反馈Reward 实验成果:使用同一个网络学习玩Atari 2600 游戏.在測试的7个游戏中6个超过了以往的方法而且好几个超

(转) Playing FPS games with deep reinforcement learning

Playing FPS games with deep reinforcement learning 博文转自:https://blog.acolyer.org/2016/11/23/playing-fps-games-with-deep-reinforcement-learning/ When I wrote up 'Asynchronous methods for deep learning' last month, I made a throwaway remark that after

(转) Deep Reinforcement Learning: Playing a Racing Game

Byte Tank Posts Archive Deep Reinforcement Learning: Playing a Racing Game OCT 6TH, 2016 Agent playing Out Run, session 201609171218_175epsNo time limit, no traffic, 2X time lapse Above is the built deep Q-network (DQN) agent playing Out Run, trained