The 2014 ACM-ICPC Asia Regional Contest Xi'an Site K ast Defence

2014 ACM/ICPC Asia Xi'an Regional Contest总结 这次比赛中,我们队伍拿了铜奖。作为第一次参加比赛的成绩算是还可以,但是我们仍不满意。比赛中,我们正常发挥出了我们的水平,但是没有超水平发挥。 比赛的旅行准备工作没有出问题,没有忘带东西之类的事情出现。以后可以参考这次的准备。 比赛开始后我们分散看题,争取对各题尽快定位。 A因为题干较长,在确定是签到题之后又三个人一起看了一遍题确定对题意的理解。 B一眼看过去就知道是模拟。因为也在玩这个游戏 阅读详情

ProblemK. Last Defence


Description

Given two integersA and B. Sequence S is defined as follow:

• S0 = A

• S1 = B

• Si = |Si−1 −Si−2| for i ≥ 2

Count the number ofdistinct numbers in S.


Input

The first line ofthe input gives the number of test cases, T. T test cases follow. Tis about 100000.

Each test caseconsists of one line - two space-separated integers A, B. (0 ≤ A, B≤ 1018).


Output

For each test case,output one line containing “Case #x: y”, where x is the test casenumber (starting from 1) and y is the number of distinct numbers inS.


Samples

Sample Input

Sample Output

2

7 4

3 5

Case #1: 6

Case #2: 5



题目大意:给定两个数,每次由两个数的差得到一个新的数,求一共能得到几个不同的数。
解题思路:因为最终会得到X X 0这样循环出现的数,所以不同数字个数是有限个的。因为数字太大,直接求会T,正解是辗转相除法。我的方法是观察找规律,根据两个数的差值和两个数之间的关系,可以得到后面数字的个数。
代码如下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long
#define mod=1e9+7; 
using namespace std;
const int maxn=10000005;
ll ans;
void getans(ll a,ll b)
{
    if(a==b)
        return ;
    ll c=a-b;   //根据a,c,b之间的关系可以得到一段长度为cur的等差数列,长度即数字个数
    ll cur=a/c;   //得到多段等差数列
    a=a-(cur-1)*c;
    ans+=cur-1;
    getans(a,c);
}
int main(void)
{
    int t;
    ll x,y,a,b,c;
    scanf("%d",&t);
    for(int ca=1;ca<=t;ca++)
    {
        ans=0;
        scanf("%I64d%I64d",&x,&y);
        if(x==y)   //x,y相同时特判一下
        {
            if(x==0)
                printf("Case #%d: 1\n",ca);
            else
                printf("Case #%d: 2\n",ca);
            continue;
        }
        if(x>y)   //保证得到的a,b值是a>b
        {
            ll c=x-y;
            a=x;
            if(c>y)
                b=c;
            else
                b=y;    
        }
        else
        {
            ll c=y-x;
            a=y;
            if(c>x)
                b=c;
            else
                b=x;
        }
        getans(a,b); 
        printf("Case #%d: %I64d\n",ca,ans+2);
    }   
}

正解辗转相除法:

#include <cstdio>
#include <cstring>
#define ll long long 
using namespace std;
ll ans;
void get_ans(ll a,ll b)
{
    if(b==0)
        return;
    ans+=a/b;
    get_ans(b,a%b);
}
int main()
{
    int t;
    ll a,b;
    scanf("%d",&t);
    for(int ca=1;ca<=t;ca++)
    {
        ans=0;
        scanf("%I64d%I64d",&a,&b);
        if(a==0||b==0)
        {     
            if(a==0&&b==0)       
                printf("Case #%d: 1\n",ca);
            else
                printf("Case #%d: 2\n",ca);
            continue;
        }
        if(a>b)
            get_ans(a,b);
        else
            get_ans(b,a);
        printf("Case #%d: %I64d\n",ca,ans+1);
    }
    return 0;
}



FPGA实战:从零构建eMMC控制器(Verilog篇) 本文详细介绍了如何使用Verilog从零构建FPGA上的eMMC控制器,涵盖eMMC接口基础、命令系统解析、关键模块设计及性能优化技巧。通过实战案例,帮助开发者掌握高速数据存储解决方案,提升嵌入式系统开发能力。 阅读详情

相关推荐

PX4代码解析(1)

前言 做pixhawk飞控有一段时间了,但在学习过程中遇到许多困难,目前网上找不到比较完整的PX4学习笔记,我打算结合自己理解,写写自己对PX4源码的理解,不一定对,只是希望与各位大佬交流交流,同时梳理一下无人机知识。 目前打算分享以下几个内容:代码架构;通信协议;姿态解算算法,控制算法。先这样,后面想到再加。本章先来聊聊px4代码结构 一、代码整体结构 既然要聊px4代码结构,那就先把px4代码结构图放出来,因为px4源码仍然在不断更新迭代,因此老版本与新版本目录结构可能有些不同,我的代码解析参考版本为V

qq_36903625的博客 1万+

UVA-7045 Last Defence (辗转相除法)

Given two integers A and B. Sequence S is de ned as follow: • S0 = A • S1 = B • Si = |S (i - 1)  — S(i - 2)| , for i &gt;= 2 Count the number of distinct numbers in S.Input The rst line of the input g...

Gamer_Lee的博客 359

Android Profiler实战:如何用CPU分析工具揪出卡顿元凶(附线程状态解读)

本文深入解析Android Profiler中的CPU分析工具,重点聚焦线程活动监控。通过解读线程状态时间轴上的绿、黄、灰三色含义,并结合实战案例,指导开发者精准定位导致界面卡顿的CPU密集型或I/O阻塞代码,有效提升应用性能与用户体验。

weixin_29197699的博客 372

CF Gym 100548K Last Denfence(辗转相除法)

                                             Last Denfence  Last Defence Description     Given two integers A and B. Sequence S is defined as follow:     • S0 = A     • S1 = B     • Si = |Si−1 − Si−2...

凡心所向,素履所往,生如逆旅,一苇以航 455

SystemRDL:从寄存器描述到自动化生成的完整指南

本文详细介绍了SystemRDL如何通过“一份描述,多处生成”的理念,彻底解决芯片与FPGA设计中手动维护寄存器带来的不一致与低效问题。文章提供了从语言快速上手、核心组件讲解到使用PeakRDL工具链实现自动化代码与文档生成的完整实战指南,帮助硬件工程师构建高效、可靠的寄存器开发流程。

weixin_29243279的博客 656

安防相机宽动态(WDR)技术解析:从原理到实战应用

本文深入解析安防相机宽动态(WDR)技术原理,对比多次曝光与DOL-WDR等实现方式,并区分硬件WDR与数字WDR(DWDR)的本质差异。文章重点阐述了WDR在逆光出入口、夜间道路监控等五大典型场景的实战应用与调参技巧,旨在帮助用户根据实际需求正确选择与配置,确保监控系统在复杂光线下清晰成像。

weixin_29191081的博客 427

The 2014 ACM-ICPC Asia Xi’an Regional Contest Problem F. Color(二项式反演)

                                                 Problem F. Color   传送门 题意:长度为n的一个连续串让你染色,使得相邻位置的颜色不能一样,且串中恰好一共出现k种颜色,问若是你有m种颜色(m&gt;=k),一共有多少种染色方法满足给定条件. 我们易推得如果仅仅是要求相邻位置的颜色不一样那么              ...

喵喵喵? 686

告别龟速计算!用Python的fengwo模块5分钟搞定通达信COST/WINNER函数(附完整代码)

本文介绍如何使用Python的fengwo模块高效复现通达信的COST和WINNER函数,解决量化交易中的计算精度和性能问题。通过C++核心算法和多线程优化,计算速度提升显著,误差低于0.5%,并支持与通达信DLL无缝集成,适用于实盘交易策略开发。

weixin_42533751的博客 599

2014-2015 ACM-ICPC, Asia Xian Regional Contest G

Problem G. The Problem to Slow Down You Description After finishing his homework, our problem setter Federmann decided to kill time by hanging around online. He found a cool chat room that discusse

CRZbulabula的博客 1089

固定效应模型-以stata为工具

固定效应模型(Fixed Effects Model)是一种面板数据分析方法,通过引入个体固定效应来控制个体间的异质性,并更准确地估计解释变量对因变量的影响。它在许多经济、社会科学和健康研究中被广泛应用。

侯小啾技术博客 2837

【24E】SWT6652 wifi驱动加载失败问题分析及解决方案

修改驱动配置Kconfig。是由于内存分配失败导致。

wgl307293845的博客 219

The 2014 ACM-ICPC Asia Anshan Regional Contest 一些题解

大型码力竞赛现场…… I - Osu! 很简单,照着题意计算一下就行 E - Hatsune Miku 是个DP,dp[i][j]代表位置i选择音符j获得的最大值,对i,i-1分成四种情况进行讨论,答案就是max(dp[n][i])max(dp[n][i])max(dp[n][i]) #include &lt;bits/stdc++.h&gt; #include&lt;cstring&gt; #i...

limn204的专栏 332

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

CF GYM 100548 Last Defence(2014ACM西安现场赛Problem K)

知识点: Ad-Hoc,辗转相除法。 题目大意: 给定数列S的首两项,要求之后的各项满足Si= |Si−1 − Si−2|(前两项差值的绝对值)。问整个数列S中不同的数字个数。 解题思路: 首先容易发现,当i足够大时,最后一定会出现“xx0xx0...”这样的重复。所以不同数字个数一定是有限的。 究其原因,对于数y和x,y一定能写成kx+b的形式,在数列的生成过程中,会出现kx+b、x、(k-1)x+b、(k-2)x+b、x、...、2x+b、x、x+b、b、x,其中出现的不同数字个数就是(kx+b)/

wujy的专栏 2353

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

2014-2015 ACM-ICPC, Asia Xian Regional Contest 6一些题解

A - Built with Qinghuai and Ari Factor 这题面真的黑出翔,判断一个数列是不是全部是3的倍数 K - Last Defence 这道题稍微模拟一下就发现和辗转相除法很相似,如果A&gt;B,那么肯定会减A/B次,这期间会产生这么多的不同的数,递归一下就行。 #include &lt;bits/stdc++.h&gt; #include&lt;cstring&gt...

limn204的专栏 327

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Codeforces 743B-Chloe and the sequence

Chloe and the sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Chloe, the same as Vladik, is a compe

wang_128的博客 686

【打CF,学算法——三星级】CF Gym 100548K Last Denfence

题目链接:Last Denfence 题面:  Last Defence Description     Given two integers A and B. Sequence S is defined as follow:     • S0 = A     • S1 = B     • Si = |Si−1 − Si−2| for i ≥ 2     Count the

David_Jett 1381

codeforces 538 B.Quasi Binary(思维题)

B. Quasi Binary time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A number is called quasibinary if its decim

ysCover 1702

CSU 1217 奇数个的那个数(异或)

1217: 奇数个的那个数 Time Limit: 2 Sec  Memory Limit: 1 MB Submit: 523  Solved: 120 [Submit][Status][Web Board] Description 给定些数字,这些数中只有一个数出现了奇数次,找出这个数。 Input 每组数据第一行n表示数字个数,1 接下来n行每行一个32位

ysCover 1111

Codeforces Beta Round #34 (Div. 2) C. Page Numbers

C. Page Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output «Bersoft» company is working on a new version of its

ysCover 1047

Codeforces Round #105 (Div. 2) B. Escape

B. Escape time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The princess is going to escape the dragon's cave, and she

ysCover 1010

Codeforces Round #313 (Div. 2) C. Gerald's Hexagon(补大三角形)

C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Gerald got a very curious hexagon for his birthda

ysCover 1010

poj 2945 Find the Clones (map+string,hash思维)

Find the Clones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7498   Accepted: 2780 Description Doubleville, a small town in Texas, was attacked by the ali

ysCover 928

noj 1052 水王争霸

水王争霸 时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte 总提交 : 182 测试通过 : 87 比赛描述 为了丰富校园网络生活,学校 BBS 举行了一次水王争霸赛。比赛开始后,选手们疯狂灌水,都想争取到水王这个荣誉称号。但学校的 BBS 是如此的不堪一击,才 1e-3 秒就超

ysCover 897

Codeforces Round #200 (Div. 2) C. Rational Resistance(脑洞思维)

C. Rational Resistance time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mad scientist Mike is building a time machine i

ysCover 877

Codeforces Round #105 (Div. 2) C. Terse princess

C. Terse princess time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output «Next please», — the princess called and cast an es

ysCover 855
上一篇: Codeforces Round #249 (Div. 2) (模拟)
下一篇: ACM ICPC 2011–2012, NEERC, Northern Subregional Contest J. John’s Inversions(合并排序求逆序数对数)
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值