NC222156. CocktailWithSnake
描述
输入描述
The first line contains a positive integer , which represents the number of groups to be tested.
Next contains lines, each row contains three integers
输出描述
For each test data, output a line of one coordinate to represent the answer. (A positive integer separated by two spaces represents the and coordinates respectively)
示例1
输入:
5 3 3 1 3 3 2 3 3 3 3 3 4 3 3 5
输出:
1 2 3 2 1
Python3 解法, 执行用时: 80ms, 内存消耗: 6876K, 提交时间: 2021-05-22 16:55:56
n = int(input()) nums = [list(map(int, input().split())) for _ in range(n)] for i in range(n): a, b, c = nums[i][0], nums[i][1], nums[i][2] d = c // a if d & 1 == 1: print(d + a - 1 - (c % a)) else: print(d + c % a)
C 解法, 执行用时: 13ms, 内存消耗: 456K, 提交时间: 2021-05-22 14:19:32
#include<stdio.h> int main(void){ long long k,x,y,t,n,m; scanf("%lld",&t); while(t--){ scanf("%lld %lld %lld",&n,&m,&k); y=k/n; if(y%2==0) x=k%n; else x=n-1-k%n; printf("%lld\n",x+y); } return 0; }
C++ 解法, 执行用时: 11ms, 内存消耗: 1144K, 提交时间: 2021-05-26 00:18:38
#include<stdio.h> int main() { long long k,x,y,t,n,m; scanf("%lld",&t); while(t--) { scanf("%lld %lld %lld",&n,&m,&k); y=k/n; if(y%2==0) x=k%n; else x=n-1-k%n; printf("%lld\n",x+y); } return 0; }