C++,codeforces,2072E,E. Do You Love Your Hero and His Two-Hit Multi-Target Attacks?

/*
codeforces,2027E,E. Do You Love Your Hero and His Two-Hit Multi-Target Attacks?
要求在平面坐标系点上n个坐标为整数且范围在[-1e9,1e9]内的点
使得满足在同一水平线或在同一垂直线上的点对的对数为k
输入k
第一行输出n,之后n行,每行输出一个点的坐标
*/

/*
我的最终方法,画出如图所示的类型的图
  .
  .
  .
  . . 
  . .
  . .
  . .
  . . .
  . . .
  . . .
  . . .
  . . .
. . . . .
  . . . .
  . . . .
  . . . .
  . . . .
  . . . .
*/
#include <iostream>
#include <cmath>
#include <vector>
void solve(){
    // n*(n-1)/2
    int k;std::cin>>k;
    if(k==0){
        std::cout<<0<<std::endl;
    }else{
        int n = 0;
        std::vector<int> cols;
        //cols.size()*n + n*(n-1)/2
        while(k>=cols.size()){
            int size = std::sqrt(2*k);
            ++size;
            while(cols.size()*size+size*(size-1)/2 > k)--size;
            k-=size*(size-1)/2;
            k-=cols.size()*size;
            n+=size;
            cols.push_back(size);
        }
        ++n;
        std::cout<<n<<std::endl;
        int x = 0;
        for(auto size : cols){
            for(int i = 0;i<size;++i){
                std::cout<<x<<' '<<i<<std::endl;
            }
            ++x;
        }
        std::cout<<-1<<' '<<cols[k]<<std::endl;
    }
}
int main(){
    int t;std::cin>>t;
    while(t--){
        solve();
    }
}



/*
ltmh的方法
输出的点的排列是一行一行的,在x轴上的投影不相交的连续的点
图示
                                    .....
                            ........
                ............
................
*/
// #include<bits/stdc++.h>
 
// void solve( ) {
//     int k;
//     std::cin >> k;
//     if (k == 0) {
//         std::cout << 0 << std::endl;
//         return;
//     }
//     std::vector<std::pair<int, int>> ans;
//     int curx = 0, cury = 0;
//     while (k) {
//         int tx = 0;
//         while (k - (tx) * (tx + 1) / 2 >= 0) {
//             tx++;
//         }
//         tx--;
//         k = k - (tx) * (tx + 1) / 2;
//         for (int i = 0;i <= tx;i++) {
//             ans.push_back({ curx + i,cury });
//         }
//         cury++;
//         curx = curx + tx + 1;
//     }
//     std::cout << ans.size( ) << std::endl;
//     for (auto& i : ans) {
//         std::cout << i.first << " " << i.second << std::endl;
//     }
 
// }
 
// int main( ) {
//     std::ios::sync_with_stdio(false);
//     std::cin.tie(nullptr);
//     int t;
//     std::cin >> t;
//     while (t--) {
//         solve( );
//     }
// }













// n的数量太多了,不合格
// void solve(){
//     //一行n个点,点对的数量n*(n-1)/2,    n
//     //n*n的方阵2*n*n*(n-1)/2 == n*n*(n-1)
//     int k;std::cin>>k;
//     if(k==0){
//         std::cout<<2<<std::endl;
//         std::cout<<1<<' '<<1<<std::endl;
//         std::cout<<2<<' '<<2<<std::endl;
//         return;
//     }else{
//         std::vector<int> squares;
//         int n = 0;
//         while(k>=4){
//             int size = std::cbrt(k);//std::cbrt(x)开三次方根
//             if((size+1)*(size+1)*size <= k){
//                 ++size;
//             }
//             squares.push_back(size);
//             k-=size*size*(size-1);
//             n+=size*size;
//         }
//         n+=2*k;
//         std::cout<<n<<std::endl;
//         int x = 0,y = 0;
//         for(auto size : squares){
//             for(int i = 0;i<size;++i){
//                 for(int j = 0;j<size;++j){
//                     std::cout<<x+j<<' '<<y+i<<std::endl;
//                 }
//             }
//             x+=size;y+=size;
//         }
//         bool flag = false;
//         for(int i = 0;i<k;++i){
//             if(flag){
//                 std::cout<<x<<' '<<y<<std::endl;
//                 std::cout<<x+1<<' '<<y<<std::endl;
//                 x+=2;y+=1;
//             }else{
//                 std::cout<<x<<' '<<y<<std::endl;
//                 std::cout<<x<<' '<<y+1<<std::endl;
//                 x+=1;y+=2;
//             }
//             flag= !flag;
//         }
//     }
// }

// void solve2(){
//     int k;std::cin>>k;
//     if(k==0){
//         std::cout<<2<<std::endl;
//         std::cout<<1<<' '<<1<<std::endl;
//         std::cout<<2<<' '<<2<<std::endl;
//         return;
//     }else{
//         std::cout<<2*k<<std::endl;
//         bool flag = 0;
//         int x = 0,y = 0;
//         for(int i = 0;i<k;++i){
//             if(flag){
//                 std::cout<<x+1<<' '<<y+1<<std::endl;
//                 std::cout<<x+2<<' '<<y+1<<std::endl;
//                 x+=2;y+=1;
//             }else{
//                 std::cout<<x+1<<' '<<y+1<<std::endl;
//                 std::cout<<x+1<<' '<<y+2<<std::endl;
//                 x+=1;y+=2;
//             }
//             flag!=flag;
//         }
//     }
// }
posted @ 2025-02-28 22:17  Kazuma_124  阅读(23)  评论(0)    收藏  举报