Find K Distinct Points with Fixed Center

Find K Distinct Points with Fixed Center

题面翻译

题目描述

我没能给这道题想出一个好的标题,所以我决定去力扣学习。

——《孙子兵法》

给你三个整数 x c x_c xc y c y_c yc k k k($ -100 \leq x_c, y_c \leq 100 $ , $ 1 \leq k \leq 1000 $)。

在一个 2D 平面上,你需要找到 k k k不同的具有整数坐标的点 ( $ x_1, y_1 $ ), ( $ x_2, y_2 $ ), $ \ldots $ , ( $ x_k, y_k $ ),满足:

  • 它们的中心$ ^{\text{∗}} $ 为 ( $ x_c, y_c $ )。
  • 1 1 1 k k k,对于每一个 i i i,都有 $ -10^9 \leq x_i, y_i \leq 10^9 $。

可以证明至少有一组 k k k 个不同的点满足以上条件。

$ ^{\text{∗}} $ 任意 $ k $ 个点 ( $ x_1, y_1 $ ), ( $ x_2, y_2 $ ), $ \ldots $ , ( $ x_k, y_k $ ) 的中心是 $ \left( \frac{x_1 + x_2 + \ldots + x_k}{k}, \frac{y_1 + y_2 + \ldots + y_k}{k} \right) $。

输入格式

第一行包含一个正整数 $ t $ ( $ 1 \leq t \leq 100 $ ),表示测试数据的组数。

每组测试数据包含三个整数 $ x_c $ , $ y_c $ 和 $ k $ ( $ -100 \leq x_c, y_c \leq 100 $ , $ 1 \leq k \leq 1000 $ ) 表示中心的坐标和你需要找到不同点的个数。

保证 $ k $ 的总和不超过 $ 1000 $。

输出格式

对于每一个测试点,输出 $ k $ 行,第 $ i $ 行包含两个以空格分隔的整数,$ x_i $ 和 $ y_i $,( $ -10^9 \leq x_i, y_i \leq 10^9 $ ),表示第 i i i 个点的坐标。

如果有多个答案,输出任意一个即可。可以证明在给定条件下必然有解。

提示

对于第一组测试数据,$ \left( \frac{10}{1}, \frac{10}{1} \right) = (10, 10) $ .

对于第二组测试数据,$ \left( \frac{-1 + 5 - 4}{3}, \frac{-1 -1 + 2}{3} \right) = (0, 0) $ .

翻译:@imnotcfz

题目描述

I couldn’t think of a good title for this problem, so I decided to learn from LeetCode.

— Sun Tzu, The Art of War

You are given three integers $ x_c $ , $ y_c $ , and $ k $ ( $ -100 \leq x_c, y_c \leq 100 $ , $ 1 \leq k \leq 1000 $ ).

You need to find $ k $ distinct points ( $ x_1, y_1 $ ), ( $ x_2, y_2 $ ), $ \ldots $ , ( $ x_k, y_k $ ), having integer coordinates, on the 2D coordinate plane such that:

  • their center $ ^{\text{∗}} $ is ( $ x_c, y_c $ )
  • $ -10^9 \leq x_i, y_i \leq 10^9 $ for all $ i $ from $ 1 $ to $ k $

It can be proven that at least one set of $ k $ distinct points always exists that satisfies these conditions.

$ ^{\text{∗}} $ The center of $ k $ points ( $ x_1, y_1 $ ), ( $ x_2, y_2 $ ), $ \ldots $ , ( $ x_k, y_k $ ) is $ \left( \frac{x_1 + x_2 + \ldots + x_k}{k}, \frac{y_1 + y_2 + \ldots + y_k}{k} \right) $ .

输入格式

The first line contains $ t $ ( $ 1 \leq t \leq 100 $ ) — the number of test cases.

Each test case contains three integers $ x_c $ , $ y_c $ , and $ k $ ( $ -100 \leq x_c, y_c \leq 100 $ , $ 1 \leq k \leq 1000 $ ) — the coordinates of the center and the number of distinct points you must output.

It is guaranteed that the sum of $ k $ over all test cases does not exceed $ 1000 $ .

输出格式

For each test case, output $ k $ lines, the $ i $ -th line containing two space separated integers, $ x_i $ and $ y_i $ , ( $ -10^9 \leq x_i, y_i \leq 10^9 $ ) — denoting the position of the $ i $ -th point.

If there are multiple answers, print any of them. It can be shown that a solution always exists under the given constraints.

样例 #1

样例输入 #1

4
10 10 1
0 0 3
-5 -8 8
4 -5 3

样例输出 #1

10 10
-1 -1
5 -1
-4 2
-6 -7
-5 -7
-4 -7
-4 -8
-4 -9
-5 -9
-6 -9
-6 -8
1000 -1000
-996 995
8 -10

提示说明

For the first test case, $ \left( \frac{10}{1}, \frac{10}{1} \right) = (10, 10) $ .

For the second test case, $ \left( \frac{-1 + 5 - 4}{3}, \frac{-1 -1 + 2}{3} \right) = (0, 0) $ .

代码内容

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <stack>//栈
// #include <deque>//队列
// #include <queue>//堆/优先队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll t;
    cin>>t;
    
    while(t--)
    {
        ll x,y,k;
        cin>>x>>y>>k;
        
        ll a=0,b=0;
        ll m=-1000;
        ll n=k;
        while(--k)
        {
            a+=m;
            b+=m;
            cout<<m<<" "<<m<<endl;
            m++;
        }
        cout<<x*n-a<<" "<<y*n- b<<endl;
    }
    
   return 0;
}



    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Pretty Boy Fox

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

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

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

打赏作者

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

抵扣说明:

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

余额充值