1996: Super Addition

本文介绍了一个编程挑战——处理极大整数的加法运算。输入包含多个测试案例,每个案例有多行数字,需实现算法计算这些巨大数值的和,并正确输出结果。文章提供了完整的C语言程序代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1996: Super Addition


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
60s10240K2026141Standard

The sum of any two integers A=a1a2...an and B=b1b2...bn is very easy to make(of course ai or bi may be zero), especially to programmers, because they can let the power overwhelming computer help them to do the work. But what if n becomes huge? For example, n exceeds 2^32. For such A and B, a program is unable to store them, say nothing of making their sum. But if you are clever enough, who can say you won't do the work?

Input

The input contains several test cases. Each test case consists of N+1 lines. The first line of each test case contains a single integer N(N<=10000000). The next N lines each contains two integers(from 0 to 9) representing ai and bi. For example, if A=1234 and B=567, then the input may be like this:

4
1 0
2 5
3 6
4 7

The last test case marks by N=-1, which you should not proceed.

Output

For each test case, print the sum of A and B in a single line.

Notice: The output integer may be very large(containing more than N digits).

Sample Input

4
1 0
2 5
3 6
4 7
-1

Sample Output

1801

 


This problem is used for contest: 3 

 

 

 

#include<stdio.h>
#include<string.h>
const int max=2200000;
int a[max+1];
int main()
{
    int i,j,aa,b,n,ta,tb;
    while(scanf("%d",&n)==1&&n!=-1)
    {
        memset(a,0,sizeof(a));
            ta=tb=0;
            for(i=0;i<n%9;i++)
            {
                scanf("%d%d",&aa,&b);
                ta=ta*10+aa;
                tb=tb*10+b;
            }
            a[max-n/9]=ta+tb;

        int l=max-n/9;
        for(i=0;i<n/9;i++)
        {
            ta=tb=0;
            for(j=0;j<9;j++)
            {
                scanf("%d%d",&aa,&b);
                ta=ta*10+aa;
                tb=tb*10+b;
            }
            a[++l]=ta+tb;
        }
        for(i=max;i>=0;i--)
        {
            if(a[i]>=1000000000)
            {
                a[i-1]+=1;
                a[i]-=1000000000;
            }
        }
        int flag=0;
        int mm=max;
        for(i=0;i<=max;i++)
        {
            if(a[i]){ mm=i;break;}
        }
        printf("%d",a[mm]);
        for(i=mm+1;i<=max;i++)
        {
            printf("%09d",a[i]);
        }
        printf("/n");
    }
    return 0;
}

请你将上面你所提出来的方法,与下面我的方法进行融合创新,要科学、有效,同时合理可靠,: import torch import torch.nn as nn from models.common import Conv, Bottleneck class DynamicChannelAttention(nn.Module): """动态通道注意力模块(双路径特征聚合)""" def __init__(self, channels, reduction=16): super().__init__() mid = channels // reduction self.avg_pool = nn.AdaptiveAvgPool2d(1) self.max_pool = nn.AdaptiveMaxPool2d(1) self.fc = nn.Sequential( nn.Conv2d(channels, mid, 1, bias=False), nn.ReLU(), nn.Conv2d(mid, channels, 1, bias=False), nn.Sigmoid() ) def forward(self, x): avg_out = self.fc(self.avg_pool(x)) max_out = self.fc(self.max_pool(x)) return x * (avg_out + max_out) / 2 # 双路径加权融合 class DeformableSpatialAttention(nn.Module): """可变形空间注意力模块""" def __init__(self, channels, kernel_size=7): super().__init__() self.conv = nn.Sequential( nn.Conv2d(channels, channels//2, 3, padding=1, groups=channels//4), nn.ReLU(), nn.Conv2d(channels//2, 1, kernel_size, padding=kernel_size//2, groups=1), nn.Sigmoid() ) def forward(self, x): return x * self.conv(x) class LiteBottleneck(nn.Module): """轻量化Bottleneck结构""" def __init__(self, c1, c2, shortcut=True, g=1, e=0.5): super().__init__() hidden = int(c2 * e) self.cv1 = Conv(c1, hidden, 1, 1) self.cv2 = Conv(hidden, hidden, 3, 1, groups=g) self.cv3 = Conv(hidden, c2, 1, 1) self.add = shortcut and c1 == c2 def forward(self, x): return x + self.cv3(self.cv2(self.cv1(x))) if self.add else self.cv3(self.cv2(self.cv1(x))) class C3_Optimized(nn.Module): """轻量级C3模块(集成动态注意力)""" def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5, reduction=16): super().__init__() c_ = int(c2 * e) # 输入分支 self.cv1 = Conv(c1, c_, 1, 1) self.cv2 = Conv(c1, c_, 1, 1) # 轻量化Bottleneck序列 self.m = nn.Sequential( *[LiteBottleneck(c_, c_, shortcut, g, e) for _ in range(n)] ) # 动态注意力融合模块 self.att = nn.Sequential( DynamicChannelAttention(c_ * 2, reduction), DeformableSpatialAttention(c_ * 2) ) # 跨阶段特征校准 self.fuse = Conv(c_ * 2, c2, 1, 1) def forward(self, x): # 分支特征提取 x1 = self.cv1(x) x2 = self.cv2(x) # 带注意力的Bottleneck处理 x1 = self.m(x1) # 跨阶段特征融合 fused = torch.cat([x1, x2], dim=1) fused = self.att(fused) return self.fuse(fused)
最新发布
07-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值