2022.9.4———HZOI【CSP-S模拟2(联考)】
作者:互联网
\(Write\ In\ Front\)
\(Rank33/43\) 只拿了 \(13 + 25 + 32 + 7 = 77pts\)
\(lyin\)大佬三百多分,我一百不到,我太菜了
\[ \Huge \mathbf{水博客警告!} \]这篇博客里基本没写啥
\(\mathfrak{T1}\ 谜之阶乘\)
蜜汁阶乘太草了
注意到a-b最大差值不会超过\(20\),因为\(20!\)已经达到了10^18级别
既然这个差值这么小,那么就可以枚举这个差值,然后套个二分找\(a_i\ b_i\)
作总结
\[ 枚举差值delta = a-b,然后枚举a_i,得到b_i = a_i - delta,然后check()算出res,二分判断l、r左右移动 \]然后就切了
怕爆long long
可以开__int128
,__int128
手写个输入输出就行
T1
#include <iostream>
#include <cctype>
#include <vector>
#define GMY (520&1314)
#define FBI_OPENTHEDOOR(x) freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout);
#define re register int
#define char_phi signed
#define MARK cout << "###"
#define MARKER "@@@"
#define LMARK "!!!~~~"
#define ZY " qwq "
#define _ ' '
#define Endl cout << '\n'
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define N 25
#define INF 1000000000000000000
using namespace std;
inline __int128 read(){
__int128 x(0); char c;
while (!isdigit(c = getchar()));
do{
x = (x << 3) + (x << 1) + (c & 15);
}while (isdigit(c = getchar()));
return x;
}
void ot(__int128 x){
if (x > 9) ot(x/10);
putchar(x%10+'0');
}
__int128 T, n;
struct Final_Ans{__int128 ai, bi;};
vector<Final_Ans> a;
inline __int128 check(__int128 delta, __int128 mid){
__int128 res(1);
for (__int128 i = mid ; i >= mid-delta+1 ; -- i){
res = res * i;
if (res > INF)
return INF+1;
}
return res;
}
inline void Clean(){
a.clear();
}
void work(){
Clean();
n = read();
if (n == 1)
{puts("-1"); return ;}
for (__int128 i = 20, l, r, mid, ans ; i >= 1 ; -- i){
l = i+1, r = INF, ans = INF+1;
while (l <= r){
mid = ((l+r) >> 1);
if (check(i, mid) < n)
l = mid+1;
else if (check(i, mid) > n)
r = mid-1;
else
{ans = mid; break;}
}
if (ans <= INF)
a.push_back((Final_Ans){ans, ans-i});
}
ot((__int128)a.size()), putchar('\n');
for (re i = 0 ; i < a.size() ; ++ i){
ot(a[i].ai), putchar(' '), ot(a[i].bi), putchar('\n');
}
}
// #define IXINGMY
char_phi main(){
#ifdef IXINGMY
FBI_OPENTHEDOOR(a);
#endif
T = read();
while (T --)
work();
return GMY;
}
\(\mathfrak{T2}\ 子集\)
这玩意好玩
首先对于\(\frac{n}{k}\)为偶数就比较显然,小学奥数。就比如这个,\(1\ 2\ 3\ |\ 4\ 5\ 6\),显然选\(1+6,2+5,3+4\),类似的更大也是这么选
对于正解就是这个的拓展
但是我不是特别理解,所以贺了题解
等\(dbx\)理解了我再去烦他
T2
#include <iostream>
#include <vector>
#define GMY (520&1314)
#define FBI_OPENTHEDOOR(x) freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout);
#define re register int
#define char_phi signed
#define MARK cout << "###"
#define MARKER "@@@"
#define LMARK "!!!~~~"
#define ZY " qwq "
#define _ ' '
#define Endl cout << '\n'
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define N 1000005
using namespace std;
inline void Fastio_setup(){ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL), cerr.tie(NULL);}
int T, n, K, len;
vector<int> a[N];
inline void doi(int id, int kuainum){
for (re i = 1 ; i <= kuainum ; ++ i){
if ((i & 1) == 1)
for (re j = 1 ; j <= K ; ++ j)
a[j].push_back(++ id);
else
for (re j = K ; j >= 1 ; -- j)
a[j].push_back(++ id);
}
}
inline void doit(){
int id(0);
for (re i = 1 ; i <= K ; ++ i)
a[i].push_back(++ id);
for (re i = (K/2)+2 ; i <= K ; ++ i)
a[i].push_back(++ id);
for (re i = 1 ; i <= (K/2)+1 ; ++ i)
a[i].push_back(++ id);
for (re i = 1 ; i <= K ; ++ i)
a[i].push_back(3*(3*K+1)/2 - a[i][0] - a[i][1]);
}
void work(){
// Clean();
cin >> n >> K; len = n/K;
if (K == 1){
cout << "Yes" << '\n';
for (re i = 1 ; i <= n ; ++ i)
cout << i << _;
Endl;
return ;
}
if (((n & 1) == 0 and (len & 1) == 1) or len == 1)
{cout << "No" << '\n'; return ;}
for (re i = 1 ; i <= K ; ++ i)
vector<int>().swap(a[i]);
cout << "Yes" << '\n';
if ((len & 1) == 0)
doi(0, len);
else
doit(), doi(K*3, len-3);
for (re i = 1 ; i <= K ; ++ i){
for (re j = 0 ; j < len ; ++ j)
cout << a[i][j] << _;
Endl;
}
}
// #define IXINGMY
char_phi main(){
#ifdef IXINGMY
FBI_OPENTHEDOOR(a);
#endif
Fastio_setup();
cin >> T;
while (T --)
work();
return GMY;
}
\(\mathfrak{T3}\ 混凝土粉末\)
我水
\(\mathfrak{T4}\ 排水系统\)
嘉晚饭是真的
标签:__,int,res,mid,CSP,HZOI,int128,联考,define 来源: https://www.cnblogs.com/charphi/p/16699343.html