2248: Sequence

本文介绍了一种用于预测整数数列中下一个数值的算法。该算法通过计算数列中各元素之间的差值来推断数列的规律,并据此预测数列的下一个数值。文章包含完整的算法实现代码。

2248: Sequence


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K340105Standard
Jojer has been given a sequence of integers, and he should find the next integer of the sequence. Can you help him? Just see the samples to understand the problem.

Input

The input consists of several test cases. Each case will give you an integer N ( 0 < N < 21 ) which indicates the number of the integers on the first line. And N integers on the next line.

Output

You should output the next integer of the sequence.

Sample Input

2
10 12

3
7 8 11

4 
9 9 9 9

1
2

Sample Output

14
16
9
2

 

Problem Source: fennec

#include<stdio.h>
int main()
{
    int a[50][50];
    int n,i,j;
    while(scanf("%d",&n)==1)
    {
        for(i=0;i<n;i++) scanf("%d",&a[0][i]);
        for(i=1;i<n;i++) for(j=0;j+i<n;j++) a[i][j]=a[i-1][j+1]-a[i-1][j];
        a[n-1][1]=a[n-1][0];
        for(i=n-2;i>=0;i--)  a[i][n-i]=a[i][n-i-1]+a[i+1][n-i-1];
        printf("%d/n",a[0][n]);
    }
    return 0;
}

[16:24:58.340987] Data 61-88-A2-54-55-00-00-42-D3-48-22-00-00-42-D3-1E-6B-28-37-DF-03-00-62-E9-2D-62-1A-77-5F-D8-00-A5-10-32-C8-6E-B2-49-EF-0B-69-C8-B4-54-FF-FF Frame Information: (46 bytes) Packet Number: 12541 Protocol: ZigBee Timestamp: 16:24:58.340987 Time Delta: 0.152296 Channel: 22 Length: 46 Link Quality: -9 dBm Source: USB9156 Layer: NWK Status: Encrypted MAC Header: (9 bytes) Frame Control: 0x8861 ···· ···· ···· ·001 = Frame Type: [0x1] Data ···· ···· ···· 0··· = Security Enabled: [0x0] No ···· ···· ···0 ···· = Frame Pending: [0x0] No ···· ···· ··1· ···· = Acknowledgement Request: [0x1] Yes ···· ···· ·1·· ···· = Intra-PAN: [0x1] Yes ···· ··00 0··· ···· = Reserved: 0x0 ···· 10·· ···· ···· = Destination Addr Mode: [0x2] 16-bit Short Address ··00 ···· ···· ···· = Reserved: 0x0 10·· ···· ···· ···· = Source Addr Mode: [0x2] 16-bit Short Address Sequence Number: 162 Destination PAN ID: 0x5554 Destination Address: 0x0000 Source Address: 0xD342 MAC Payload: (35 bytes) NWK Header: 0x6B1ED34200002248 Frame Control: 0x2248 ···· ···· ···· ··00 = Frame Type: [0x0] Data ···· ···· ··00 10·· = Protocol Version: 0x2 ···· ···· 01·· ···· = Route Discovery: [0x1] Enabled ···· ···0 ···· ···· = Multicast Flag: [0x0] Unicast or Broadcast ···· ··1· ···· ···· = Security Enabled: [0x1] Yes ···· ·0·· ···· ···· = Source Route Included: [0x0] No ···· 0··· ···· ···· = Destination IEEE Address Included: [0x0] No ···0 ···· ···· ···· = Source IEEE Address Included: [0x0] No ··1· ···· ···· ···· = Device Initiator: [0x1] Yes 00·· ···· ···· ···· = Reserved: 0x0 Destination Address: 0x0000 Source Address: 0xD342 Radius: 0x1E Sequence Number: 107 NWK Aux Header: (14 bytes) Network Security Control: 0x28 ···· ·000 = Network Security Level: [0x0] None ···0 1··· = Key NWK ID: [0x1] Network Key ··1· ···· = Extended Nonce: [0x1] Yes 00·· ···· = Reserved: 0x0 NWK Frame Counter: 253751 Source Address: D8:5F:77:1A:62:2D:E9:62 NWK Key Sequence Number: 0 NWK Payload: (9 bytes) Encrypted Payload: (9 bytes) NWK MIC: 0x69C8B454 MAC Footer: 0xFFFF Frame Check Sequence: 0xFFFF
07-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值