A. Strange Table

该博客主要探讨了一种矩形表格的两种不同编号方式:按列优先和按行优先。对于给定的按列优先编号的单元格,我们需要计算其在按行优先编号系统下的位置。博主提供了一个C++代码实现来解决这个问题,并通过示例展示了算法的正确性。
摘要由CSDN通过智能技术生成

A. Strange Table

题目:

Polycarp found a rectangular table consisting of n rows and m columns. He noticed that each cell of the table has its number, obtained by the following algorithm “by columns”:
cells are numbered starting from one;
cells are numbered from left to right by columns, and inside each column from top to bottom;
number of each cell is an integer one greater than in the previous cell.
For example, if n=3 and m=5, the table will be numbered as follows:
123456789101112131415
However, Polycarp considers such numbering inconvenient. He likes the numbering “by rows”:
cells are numbered starting from one;
cells are numbered from top to bottom by rows, and inside each row from left to right;
number of each cell is an integer one greater than the number of the previous cell.
For example, if n=3 and m=5, then Polycarp likes the following table numbering:
161127123813491451015
Polycarp doesn’t have much time, so he asks you to find out what would be the cell number in the numbering “by rows”, if in the numbering “by columns” the cell has the number x?
Input
The first line contains a single integer t (1≤t≤104). Then t test cases follow.
Each test case consists of a single line containing three integers n, m, x (1≤n,m≤106, 1≤x≤n⋅m), where n and m are the number of rows and columns in the table, and x is the cell number.
Note that the numbers in some test cases do not fit into the 32-bit integer type, so you must use at least the 64-bit integer type of your programming language.
Output
For each test case, output the cell number in the numbering “by rows”.

输入

5
1 1 1
2 2 3
3 5 11
100 100 7312
1000000 1000000 1000000000000

输出

1
2
9
1174
1000000000000

代码:
上网比较其他大佬的代码之后,觉得还是我的代码香

#include<stdio.h>
int main()
{
    long long int a,b,c,d,x=1,i,j,s[1010];
    scanf("%lld",&a);
    while(a--)
    {
        scanf("%lld%lld%lld",&b,&c,&d);
        i=d/b+1;
        j=d%b;
        if(j==0)
            i--,j=b;
        //printf("%lld %lld \n",j,i);
        printf("%lld\n",(j-1)*c+i);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Prime me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值