D Digit Size

本文详细解读了HDOJ3575中的数字LC显示屏尺寸变换问题,通过实例分析了如何改变显示屏中数字的大小,并提供了实现该功能的代码示例。

Problem Description
Digital LC-display is widely used in many different fields such as electronic calculator, electronic watch, digital instruments, etc. A simulated example of the numbers represented by digital LC-display device is shown as follows:

Each number represented by LC-display above is composed of s "-" signs for the horizontal segments and s "|" signs for the vertical ones, and each number exactly occupies s+2 columns and 2s+3 rows. Your task is to change the size of the original numbers by changing "s" — the number of signs.
 

Input
The first line of input contains a number t, which means there are t cases of the test data.
The input contains several lines, 2s + 4 for each number to be displayed. The first line of each case contains two integer s and t (1 <= s, t <= 9), where s is the original size of the numbers and t is the target size of numbers that you should output. The following 2s + 3 lines show the original number n (the digit of n will not exceed 9) you should deal with. Each digit of n will be separated by an empty column (except for the last digit).
 

Output
For each test case, output the case number and then output the target number according to the input. Output a blank line after each case.

——摘自HDOJ 3575(测试数据不好显示)


这道题题目不难!看了后题目大家都会有想法,是的,我承认不难,但想起自己当初(也才昨天而已)实现的时候真是太痛苦了!都怪自己审题不仔细,忽略了数据的大小。所以一开始时,存储输入数据的数组就只开了100*100, 呃。。写完后本地测试数据轻松过,但提交总是WA!这种情况是很郁闷的!当时改了一下午,空格换行之类的细节想得都快晕了!

到后来是心灰意冷,真没辙了。没办法了,就很无聊的把数据改大了点,草,竟奇迹般地过了。。Accept!!!有木有搞错啊……盼望了一下午啊!可还是高兴不起来,当时真的是哭笑不得。。

注意审题啊,切记……切记……


#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

int m,n;
char digit[1500][1500];

void f(int row)
{
     int i,j,k;
     int len = strlen(digit[row]);
     for(i=0; i*(m+2)+i-1<len; i++)
     {
              if(i != 0)
              printf(" ");
              printf(" ");
              for(j=0; j<n; j++)
              if(digit[row][(m+2)*i+i+1] == '-')
              printf("-");
              else printf(" ");
              printf(" ");
              }
              printf("\n");
     }
void g(int row)
{
     int i,j,k;
     int len = strlen(digit[row]);
     for(i=0; i*(m+2)+i-1<len; i++)
     {
              if(i != 0)
              printf(" ");
              printf("%c", digit[row][(m+2)*i+i]);
              for(j=0; j<n; j++)
              printf(" ");
              printf("%c", digit[row][i*(m+2)+i+m+1]);
              }
              printf("\n");
     }

int main()
{
    int cases, t;
    int i,j,k;
    
    scanf("%d", &cases);
    t = 1;
    while(t <= cases)
    {
            scanf("%d %d", &m, &n);
            
            getchar();
            for(i=0; i<2*m+3; i++)
             gets(digit[i]);

            
            printf("Case %d:\n", t);
            
            f(0);
            for(i=0; i<n; i++)
            g(1);
            f(m+1);
            for(i=0; i<n; i++)
            g(m+2);
            f(2*m+2);
            t++;
            //if(t != cases)
            printf("\n");
            }   
    return 0;
    }



帮我继续调试这个代码: #include <iostream> #include <vector> using namespace std; using ll = long long; const ll MOD = 998244353; struct BigInt { vector<int> d; // little-endian BigInt(ll v = 0) { if (v == 0) { d = {0}; } else { while (v) { d.push_back(v % 10); v /= 10; } } } void multiply(int x) { if (x == 0) { d = {0}; return; } int carry = 0; for (int& digit : d) { ll prod = (ll)digit * x + carry; digit = prod % 10; carry = prod / 10; } while (carry) { d.push_back(carry % 10); carry /= 10; } while (d.size() > 1 && d.back() == 0) d.pop_back(); } // Assume *this >= other BigInt subtract(const BigInt& other) const { BigInt res; res.d = d; int borrow = 0; for (size_t i = 0; i < res.d.size(); ++i) { int sub = (i < other.d.size()) ? other.d[i] : 0; int current = res.d[i] - borrow; if (current < sub) { res.d[i] = current + 10 - sub; borrow = 1; } else { res.d[i] = current - sub; borrow = 0; // This line is crucial for correctness, though logically it should be 0 if current >= sub } } while (res.d.size() > 1 && res.d.back() == 0) res.d.pop_back(); return res; } bool operator>(const BigInt& other) const { if (d.size() != other.d.size()) return d.size() > other.d.size(); for (int i = (int)d.size() - 1; i >= 0; --i) { if (d[i] != other.d[i]) return d[i] > other.d[i]; } return false; } bool operator<(const BigInt& other) const { if (d.size() != other.d.size()) return d.size() < other.d.size(); for (int i = (int)d.size() - 1; i >= 0; --i) { if (d[i] != other.d[i]) return d[i] < other.d[i]; } return false; } bool isZero() const { return d.size() == 1 && d[0] == 0; } }; ll mod_pow(ll base, ll exp, ll mod) { ll res = 1; base %= mod; while (exp) { if (exp & 1) res = res * base % mod; base = base * base % mod; exp >>= 1; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll a0, b0, c0, x, y, z, m; cin >> a0 >> b0 >> c0 >> x >> y >> z >> m; ll a_mod = a0 % MOD; ll b_mod = b0 % MOD; ll c_mod = c0 % MOD; BigInt A(a0), B(b0), C(c0); const ll MAX_ROUNDS = 10000; // Increased from 7500 ll rounds = m; if (m > MAX_ROUNDS) { rounds = MAX_ROUNDS; } for (ll i = 0; i < rounds; i++) { if (B.isZero()) { ll rem = m - i; a_mod = a_mod * mod_pow(x, rem, MOD) % MOD; c_mod = c_mod * mod_pow(z, rem, MOD) % MOD; cout << a_mod << " " << 0 << " " << c_mod << "\n"; return 0; } // 1. Reproduction (mod values) ll a1_mod = a_mod * (x % MOD) % MOD; ll b1_mod = b_mod * (y % MOD) % MOD; ll c1_mod = c_mod * (z % MOD) % MOD; // 2. Reproduction (high-precision) BigInt A1 = A; BigInt B1 = B; BigInt C1 = C; A1.multiply(x); B1.multiply(y); C1.multiply(z); // 3. Kill Mosquito: c2 = max(0, c1 - b1) ll c2_mod = 0; if (C1 > B1) { C = C1.subtract(B1); c2_mod = (c1_mod - b1_mod + MOD) % MOD; } else { C = BigInt(0); c2_mod = 0; } // 4. Kill Dog: b2 = max(0, b1 - a1) ll b2_mod = 0; if (B1 > A1) { B = B1.subtract(A1); b2_mod = (b1_mod - a1_mod + MOD) % MOD; } else { B = BigInt(0); b2_mod = 0; } // 5. Update for next round A = A1; a_mod = a1_mod; b_mod = b2_mod; c_mod = c2_mod; } // After simulation if (m <= MAX_ROUNDS) { cout << a_mod << " " << b_mod << " " << c_mod << "\n"; } else { // If m > MAX_ROUNDS, assume B.isZero() based on problem constraints for large m ll rem = m - MAX_ROUNDS; a_mod = a_mod * mod_pow(x, rem, MOD) % MOD; c_mod = c_mod * mod_pow(z, rem, MOD) % MOD; cout << a_mod << " " << 0 << " " << c_mod << "\n"; } return 0; } 题面: # U619055 Roàçhs Dogs and Mosquitos I ## 题目背景 在 $Sirius$ 上有三种动物,$Roàçh$,$Dog$ 和 $Mosquito$,$Roàçh$ 会谋杀 $Dog$ ,$Dog$ 会谋杀 $Mosquito$。 ## 题目描述 初始有 $a$ 只 $Roàçh$,$b$ 只 $Dogs$ 和 $c$ 只 $Mosquito$ ,共有 $m$ 个时刻,每个时刻会按顺序发生以下事件: $1.$ $a\leftarrow a\times x$ $b\leftarrow b\times y$ $c\leftarrow c\times z$ $2.$ 你以任意顺序排列这些动物。 $3.$ 每只 $Dog$ 按从左到右的顺序进行操作,每次操作为找一只**在它右边的** $Mosquito$ 并谋杀它,接着这只 $Mosquito$ 会消失,若它右边没有 $Mosquito$ ,它不会进行操作。 $4.$ 每只 $Roàçh$ 按从左到右的顺序进行操作,每次操作为找一只**在它右边的** $Dog$ 并谋杀它,接着这只 $Dog$ 会消失,若它右边没有 $Dog$ ,它不会进行操作。 对于每次排列,你的排列方法都会使**这一次**剩下的总动物数尽量少。 现在从初始状态总共过了 $m$ 个时刻,问最后每种动物的数量是多少,对 $998244353$ 取模 ## 输入格式 $a$ $b$ $c$ $x$ $y$ $z$ $m$ ## 输出格式 三个用空格隔开的数,分别为最终 $Roàçh$ ,$Dog$,$Mosquito$的数量。 ## 输入输出样例 #1 ### 输入 #1 ``` 1 1 1 2 6 15 1 ``` ### 输出 #1 ``` 2 4 9 ``` ## 输入输出样例 #2 ### 输入 #2 ``` 2 1 1 1 1 1 2491738747 ``` ### 输出 #2 ``` 2 0 0 ``` ## 输入输出样例 #3 ### 输入 #3 ``` 1 47 49 1 49 49 4949 ``` ### 输出 #3 ``` 1 59008212 0 ``` ## 输入输出样例 #4 ### 输入 #4 ``` 2 3 49 2 3 49 2401 ``` ### 输出 #4 ``` 566916249 0 30663132 ``` ## 说明/提示 $49$分 $1≤a,b,c≤2$ $49$分 $1≤x,y,z≤2$ $49$分 $1≤m≤49$ 额外的$49$分 $1≤m≤249$ 额外的$2\times49+2$分 $1≤m≤7.47 \times 10^{3}$ $1≤a,b,c≤3$ $1≤x,y,z≤3$ 额外的$2\times49+2$分 $1≤m≤7.47 \times 10^{3}$ 额外的$49$分 $a=b=c=1$ 额外的$49$分 $x=y=z=1$ 额外的$2\times49+2+2$分 $1≤a,b,c≤3$ $1≤x,y,z≤3$ $2*49$%$+2$% $1≤a,b,c≤49$ $2*49$%$+2$% $1≤x,y,z≤49$ $2*49$%$+2$% $1≤m≤249 \times 2^{49}$
10-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值