E. Do You Love Your Hero and His Two-Hit Multi-Target Attacks?
题目链接👈
题目描述🥰

题目思路😀
这个题目首先我们可以关注到当p(i,j)=d(i,j),这种情况只会存在两个坐标的x坐标相同或是y相同,所以当x个员工站成一条线,我们就会有x*(x-1)/2个配对。
所以题目的解法就很明显了,我们只需要关注有多少个小于k的数m(m=x*(x-1)/2,x>=0&&x<m)能够凑成k,然后构造答案即可.
但是凑成k这个代码如果书写?解释如下
//迭代计算由几个值构成k
vector<int> dev(int k)
{
vector<int>ans;
while(k>0)
{
int m=(sqrt(1+k*8)+1)/2;
while(m*(m-1)/2>k)m--;
ans.push_back(m);
k-=(m-1)*m/2;
}
return ans;
}
AC代码🧠
// Problem: E. Do You Love Your Hero and His Two-Hit Multi-Target Attacks?
// Contest: Codeforces - Codeforces Round 1006 (Div. 3)
// URL: https://codeforces.com/contest/2072/problem/E
// Memory Limit: 256 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define dev1(a) cout << #a << '=' << a << endl;
#define dev2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl;
#define dev3(a, b, c) cout << #a << " = " << a << " " << #b << " = " << b << " " << #c << " = " << c << endl;
#define dev4(a, b, c, d) cout << #a << " = " << a << " " << #b << " = " << b << " " << #c << " = " << c << " " << #d << " = " << d << endl;
#define dev5(a, b, c, d, e) cout << #a << " = " << a << " " << #b << " = " << b << " " << #c << " = " << c << " " << #d << " = " << d << " " << #e << " = " << e << endl;
#define vec(a) \
for (int i = 0; i < a.size(); i++) \
cout << a[i] << ' '; \
cout << endl;
#define darr(a, _i, _n) \
cout << #a << ':'; \
for (int ij = _i; ij <= _n; ij++) \
cout << a[ij] << ' '; \
cout << endl;
#define cin(a,n) \
for(int i=0;i<n;i++) \
cin>>a[i];
#define endl "\n"
#define pow pim
int pim(int a,int k)
{
int res=1;
if(a==0)return 0;
while(k)
{
if(k&1)res=(int)res*a;
k>>=1;
a=(int)a*a;
}
return res;
}
#define fi first
#define se second
#define caseT \
int T; \
cin >> T; \
while (T--)
// #define int long long
// #define int __int128
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 99999999;
// const int N = ;
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b)
{
return a * b / gcd(a, b);
}
inline int read()
{
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
//迭代计算由几个值构成k
vector<int> dev(int k)
{
vector<int>ans;
while(k>0)
{
int m=(sqrt(1+k*8)+1)/2;
while(m*(m-1)/2>k)m--;
ans.push_back(m);
k-=(m-1)*m/2;
}
return ans;
}
void solve()
{
int k;
cin>>k;
if (k == 0) {
cout << 0<<endl;
return ;
}
vector<int>a=dev(k);
int sum=0;
for(auto x:a)sum+=x;
cout<<sum<<endl;
int x=0,y=0;
for(auto t:a)
{
for(int i=0;i<t;i++)
{
cout<<x<<" "<<y+i<<endl;
}
y+=t;
x++;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
caseT
solve();
return 0;
}
/*
*/

posted on
浙公网安备 33010602011771号