Last Defence (run time error)
Last Defence
时间限制:1000 ms | 内存限制:65535 KB
描述
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 number of distinct numbers in S .
输入
The first line of the input gives the number of test cases, T. T test cases follow. T is about 100000.
Each test case consists of one line – two space-separated integers A, B. (0 ≤ A, B ≤ 10^18).
输出
For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the number of distinct numbers in S .
样例输入
2
7 4
3 5
样例输出
Case #1: 6
Case #2: 5
来源
Yougth
我的思路:首先这道题run time error了。。任何两个数,进行题中的运算,得出是一组数,最后肯定是x, x,0,x,x,0,x,x,0……循环的,所以当遇到x,x,0时候就停止,然后把前面的数和x,0进行处理,计算一下一共有多少不同的数。。希望大家帮看一下,这个代码运行没有错误,结果也对。
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cmath>
using namespace std;
int a[];
int main()
{
int T,i,j;
int g=;
long long A,B;
cin>>T;
while(T--)
{
scanf("%lld%lld",&A,&B);
a[]=A;
a[]=B;
i=;
while()
{
a[i]=fabs(a[i-]-a[i-]);
a[i+]=fabs(a[i]-a[i-]);
a[i+]=fabs(a[i+]-a[i]);
if(a[i]==a[i+]&&a[i+]==)
{ a[i+]=;
break;
}
i++;
}
int n=i+;
sort(a,a+i+);
for(i=;i<n-;i++)
{
if(a[i]==a[i+])
{
for(j=i;j<n-;j++)
a[j]=a[j+];
i--;
n--;
}
}
printf("Case #%d: %d\n",g,n);
g=g+;
}
return ;
}
Last Defence (run time error)的更多相关文章
- Flutter采坑之路 Run Configuration error:broken configuration due to unavailable
今天把AndroidStudio升级成了3.3.1 原先还能编译成功的Flutter工程突然连编译都不行了, 错误是 Run Configuration error:broken configurat ...
- LR 报错误: C interpreter run time error: Error -- Unresolved symbol : vuser_end解决方法
Action.c(33): Error: C interpreter run time error: Action.c (33): Error -- Unresolved symbol : vuse ...
- Unexpected exception 'Cannot run program ... error=2, No such file or directory' ... adb'
Eclipse ADT Unexpected exception 'Cannot run program' up vote 8 down vote favorite 4 I have installe ...
- Android Studio2.1 Run APP:Error: Execution failed for task
Android Studio2.1 Run APP时,遇到错误 Error: Execution failed for task ':app:clean'. Unable to delete file ...
- Run Configuration error:broken configuration due to unavailable
希望大家一起来,毕竟大家都不会使用这个Androidstudio,一起扩展这方面的知识量 http://forums.opengamma.com/t/intellij-code-compiles-bu ...
- 一次lr异常Error: C interpreter run time error: Action.c (17): Error -- memory violation : Exception ACCESS_VIOLATION received问题分析
今天qq群里人问我一个问题 人家的原始问题如下: 问题是为啥通过lr_save_string取不到参数值 由于别的问题,我也需要调试,但是没有环境,只能模拟场景,如下 他想将token变量换成lr中的 ...
- npm run dev error
Please try: rm -rf node_modules rm package-lock.json npm cache clear --force npm install windows和lin ...
- Proxy account failing to run SSIS Error (Proxy (11) is not allowed for subsystem "SSIS" and user "AB\testuser ".
USE [msdb]EXEC msdb.dbo.sp_grant_login_to_proxy @proxy_name=N'SSISProxyAgentV1', @login_name=N'WTC\E ...
- laravel npm run dev 错误 npm run dev error [npm ERR! code ELIFECYCLE]
出现此问题是node_modules出现错误,需要执行: 1 rm -rf node_modules 2 rm package-lock.json 3 npm cache clear --force ...
随机推荐
- Unix/Linux环境C编程入门教程(7) OPENBSDCCPP开发环境搭建
1. 年发起了OpenBSD 专案,希望创造一个注重安全的操作系统. 2.创建一个虚拟机. 3.选择默认的workstation10.0 4.我们选择稍后安装操作系统. 5.我们选择FreeBSD64 ...
- 去英国Savile Row 做件私人定制手工西装_GQ男士网
去英国Savile Row 做件私人定制手工西装_GQ男士网 去英国Savile Row 做件私人定制手工西装
- 枚举与剪枝_观察算式(比标准答案还要牛B)
观察算式 观察以下的算式: △△△ * △△ = △△△△ 某3位数乘以2位数,结果为4位数 要求:在9个△所代表的数字中.1~9的数字恰好每一个出现1次. 暴力破解代码: package lianx ...
- 使用rowid和rownum获取记录时要注意的问题
我们知道.rowid和rownum在Oracle中都是能够被当做伪劣使用的,主要用来定位表中特定的记录,但它们是有差别的,rowid是和行记录的物理地址相应的.而rownum则不是,是通过返回的记录集 ...
- 算法导论——lec 10 图的基本算法及应用
搜索一个图是有序地沿着图的边訪问全部定点, 图的搜索算法能够使我们发现非常多图的结构信息, 图的搜索技术是图算法邻域的核心. 一. 图的两种计算机表示 1. 邻接表: 这样的方法表示稀疏图比較简洁紧凑 ...
- Android 常用开发类库
android.app :提供高层的程序模型.提供基本的运行环境 android.content :包含各种的对设备上的数据进行访问和发布的类 android.database :通过内容 ...
- CSS:margin负数的使用
给所有div加上边框=10px之后,再给所有div设置margin-left与margin-top;以及浮动(float:left) 因此时需要鼠标悬停效果:所以设置给div设置伪类:hover,然因 ...
- Aliyun EMR 集群重启
1.如果Core节点有Down掉,ActiveNodes少于Core节点数. 处理: a.登陆到Master节点,到目录 /opt/apps/hadoop-2.7.2/sbin b.执行 ./stop ...
- 页面打开直接执行a点击事件
<script> window.onload = function(){ function autoclick(){ var url = document.getElementById(' ...
- js静态属性和静态方法
啥也不说了,直接上代码...(就是这么任性) var Animal = function(){}; Animal.name = "dog"; var a = ...