1469D - Ceil Divisions (思维)

题目

思路:首先对于1 2 3 4 . . . 2e5 我想啊,让 i=3 到 2e5-1的数全部 i/2e5 那么这些数就全为1了,1 2 1 1 1 … 1 1 2e5 ,我们这时操作次数还剩下8次(1,2,2e5没用掉),但2e5/2 8次不够用啊,所以接着我想留出一个10来现在操作次数剩下9次,2e5/10 用掉了6次,10/2又要用掉4次,比9次多了一次.那么我想这让2e5/a 用掉5次,a/2还是用4次就可以了。将a最大化16,16/2用4次,2e5/16用5次,那不就解决了嘛。但n<=16还需特殊对待。

Code:

#include<iostream>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;

int main()
{
   
    FAST;
    int t;cin >> t;
    while (t--)
    {
   
        int n;cin >> n;
        cout << n + 5 << endl;
        if (n <= 16)
        {
   
            for (int i = 3;i <= n - 1;i++) cout << i << " " << n << endl;
            for (int i = 1;i <= 8;i++)cout << n << " " << 2 << endl;
        }
        else
        {
   
            for (int i = 3;i <= 15;i++)cout << i << " " << n << endl;
            for (int i = 17;i <= n - 1;i++)cout << i << " " << n << endl;
            for (int i = 1;i <= 5;i++)cout << n << " " << 16 << endl;
            for (int i = 1;i <= 4;i++)cout << 16 << " " << 2 << endl;
        }
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
05-13 14:16
战争学院:你妈妈第一反应是骗子,我妈妈第一反应是培训贷,全国家长系统是统一的吗哈哈哈
点赞 评论 收藏
分享
03-19 09:58
河海大学 Java
最喜欢春天的奇亚籽很...:同学,是小红书不是小哄书,一眼就能看到的错误
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务