标签:ima rac sig mamicode tor 添加 自动 法则 tac
没什么好说的,求行列式的值。
\(2\le n\le10\)
数据范围很小,直接代数余子式递归求结果即可。
/**
爆ぜろリアル!弾けろシナプス!パニッシュメント?ディス?ワールド!
‘;!!!:`
.;%%%%$$$$%%%;.
.;$%;. :%;.
`||` :!.
.!: ::
:; .`.
‘` ..
`` .
.. ..
..
`;||!:‘;|%$$$%%%$$%|;‘.
‘|%%%%%%%%%%%%%%%%%%%%%%%%%%%%|:.
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$|:
.:!%%%%%%%%%%|!|%%%%$$&$$$%%%%%%%%%%%%%%%%|‘ `:‘.
‘!|%%%%%||%%%%%%%%%%%$&&&$%%%%%$$$%%%%%%%%%%%|‘‘:‘:‘.
`|%%%%%%%%%%%%%$%%%%%%%$&&&&$$%%%$$$%%%%%%%%%%%%|;:::‘::‘:`
:%%%%%%$$%%%$$%%$%%%%%%%$&&&&&$$%%|%$%%%|!|%%%%%$!‘::::;|!:‘.
.;$%%%%%$$%%%$$%%$%%%%%%%%$&&&&&$$$%%$$$%%%!!%$%%%%!::!%%%%|;‘.
.;%$%%%$$$%%%$$%%||%$$%%%%$$&&&&&&$$%%$$%%%%%%%$&&&$%$$$$%%%%|:.
;%%%%%$$$%%$&$%%!:!$$$%%%%$&$||&&&&$$%$$$%%%%%%$$$%%%%$$$$%%%|‘
:%%$%%$$$$%$&&$%!`‘|$&$%%%%$&|`.!&&&&$%$$$%%%%%%%$%%%%%%$$$$%%%;
`!%|%%%$&$%%$&$$|‘.‘|&&$%%%%$%|!‘.:$&&&$$$$%%%%%%%%%%%%%%$$$$%%%|`
;%‘:%%$&&$%$&|!|‘.`:|&&$%%%$$|‘‘‘``‘%&&&$$$%%%%%%%%%%%%%%$&&$%%%%:
`;‘ ;%%$&$%%$%;;: .:!%$%%%$|` .. .!&&&$$$%%$%%%$%$$%$$%$&$%%%$;
‘‘ .!%$&&$$%$;`:‘ `!%%%%:.... ....:$&$$$%$$%%$$$$$%$$%$&$%%%%;
.. .;%$&&&$%|:. ...;%|‘..........‘|$%%%$$%%$$&&$%$$%%%$%%%$;
;$$&&&$%!` .`....‘`.... ......`!%%%$$%%$&&&$$&&$!!$%%%$:
‘%$&&&&$!`. .`........``.......`!%%$$$%$&&&&$$&&$;;$%%%%‘
‘|$&&&&!``..```. ........`|@@|‘....`:|%%$$%%$&&&&$$&&$‘:$%%%|`
`|$&&&&$‘ .``````‘‘‘::`..........``.:%%$&$%|‘`!&&$$&&%‘:%%%%;.
;$$&&|;!:`........... .‘:`....`````!%$&&$%|;‘;&&&%|%%‘;%%%%:
‘%$&$: ...................`‘‘`...`:%%$&$$!`..!&&&$;`:;|%%%!`
;$&&%:..................... .‘:``!%$&&$;...:$&%‘`;‘ ;%%%%:
.;$&&&$:..........`‘............`!%$&&&;..‘%&&! `!%%%:
.‘:|&&&|‘‘`.............. ...‘|$&&$||$&&&|` :|‘``
.!%: `|$%|!:‘`.........`:!%$&&&&&$;‘‘. `.
.:!%$%||||||%%$$$$$$$$$%$%%$$$%%:.
`!%$%%%%%%%|||||||||||%|||||||%%%%%$%%%%|:
‘%%%%%%%%%%%%||||||||!!|||||||||||%$$%%%%%%%%$%:
:%$$$%%%$%$$%||||||||!;%%||||||||%%%%%%%%%%%%%%%%|‘
.;$%%%%$$$$$%%|||||%$$$$$%||||||||%$$%%%%%%%%%%%%%%‘
.!%%%%%%$$%%$%%|||||;;%||||||||%$$&&|!%$$%%%$$$$$%;.
.!%%%%%%%%%%%%%%$%||%%%%%%%%%%%$&$$;`;%%%%%%%%$$!.
:%%%%%%%%%%%%%%||%%%%%%%%%%%$$$%%%%%%%%%%%%%|‘
:%%%%%%%%%%$$%%%%%%%%%%%%%%%;`;%%%%%%%|:
.;%%%%%%%%%%%%%%%%%%%%%%%%%%%:..:|%%%!.
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|;:`
;$%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%‘
`|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;
.:!%$%%%%%%%%%%%%%%%%%%%%%%%%%%%%$!.
;!‘;%%%%%%%%%%%%%%%%%%%%%!:`. `|$%‘
.;%%%%%%%%%%%||%%%%%%%%%|:‘;|%$%%%%%;.
.!%%%%%%%%%%%%$$%%%%%%%%%%%%%%%%%%%%%‘
.!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;.
.;%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%‘
;%$$%%%%%%%%$$$$%%%%%%%%%%%%%%%%%%%%%‘
`|$&$%%%%%%$%$$$%%%%%%%%%%%%$%%%%%$&%%!`
:%$&$%%||%%%%$$%%%$%%%%%$$!:|%||%%$&$%%!`
**/
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#else
#include <algortmphm>
#include <btmpset>
#include <cmath>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
#endif
using namespace std;
#define inf __INT_MAX__
#define enf INT_MIN
#define INF LLONG_MAX
#define ENF LLONG_MIN
const int MAXN = 1e5 + 10;
const double pi = acos(-1.0);
const double eps = 1e-7;
typedef long long ll;
typedef unsigned long long ull;
#define zhengfu(x) ((x > eps) - (x < -eps))
#define Dprint(...) printf("%.10f\n", ##__VA_ARGS__)
#define Iprint(...) printf("%d\n", ##__VA_ARGS__)
ll mod = 20210213;
ll check(int p) {
return p % 2 ? -1 : 1;
}
ll cal(vector<ll> det[], int n) {
if (n == 1)
return det[0][0] % mod;
ll detVal = 0;
vector<ll> tempdet[n - 1];
for (int i = 0; i < n; i++) {
for (int j = 1; j < n; j++) {
tempdet[j - 1].clear();
for (int k = 0; k < n; k++)
if (k != i)
tempdet[j - 1].push_back(det[j][k]);
}
detVal = (detVal + (check(i) * det[0][i] * cal(tempdet, n - 1) % mod + mod) % mod) % mod;
}
return detVal % mod;
}
int main() {
int n;
cin >> n;
vector<ll> det[n];
for (int i = 0; i < n; i++)
for (int j = 0, x; j < n; j++) {
cin >> x;
det[i].push_back(x);
}
cout << cal(det, n);
}
消消乐,顾名思义,消着快乐,消完了就不快乐了。
一个字符矩阵,每次可以在里面将相同的字母按照一定规则消除。
规则是,连线的拐弯次数不得超过2次。
如所给图1就是合法的
图2就是不合法的
\(n\leq 20\)显然直接\(bfs\)爆搜即可
搜索方法:
/**
爆ぜろリアル!弾けろシナプス!パニッシュメント?ディス?ワールド!
‘;!!!:`
.;%%%%$$$$%%%;.
.;$%;. :%;.
`||` :!.
.!: ::
:; .`.
‘` ..
`` .
.. ..
..
`;||!:‘;|%$$$%%%$$%|;‘.
‘|%%%%%%%%%%%%%%%%%%%%%%%%%%%%|:.
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$|:
.:!%%%%%%%%%%|!|%%%%$$&$$$%%%%%%%%%%%%%%%%|‘ `:‘.
‘!|%%%%%||%%%%%%%%%%%$&&&$%%%%%$$$%%%%%%%%%%%|‘‘:‘:‘.
`|%%%%%%%%%%%%%$%%%%%%%$&&&&$$%%%$$$%%%%%%%%%%%%|;:::‘::‘:`
:%%%%%%$$%%%$$%%$%%%%%%%$&&&&&$$%%|%$%%%|!|%%%%%$!‘::::;|!:‘.
.;$%%%%%$$%%%$$%%$%%%%%%%%$&&&&&$$$%%$$$%%%!!%$%%%%!::!%%%%|;‘.
.;%$%%%$$$%%%$$%%||%$$%%%%$$&&&&&&$$%%$$%%%%%%%$&&&$%$$$$%%%%|:.
;%%%%%$$$%%$&$%%!:!$$$%%%%$&$||&&&&$$%$$$%%%%%%$$$%%%%$$$$%%%|‘
:%%$%%$$$$%$&&$%!`‘|$&$%%%%$&|`.!&&&&$%$$$%%%%%%%$%%%%%%$$$$%%%;
`!%|%%%$&$%%$&$$|‘.‘|&&$%%%%$%|!‘.:$&&&$$$$%%%%%%%%%%%%%%$$$$%%%|`
;%‘:%%$&&$%$&|!|‘.`:|&&$%%%$$|‘‘‘``‘%&&&$$$%%%%%%%%%%%%%%$&&$%%%%:
`;‘ ;%%$&$%%$%;;: .:!%$%%%$|` .. .!&&&$$$%%$%%%$%$$%$$%$&$%%%$;
‘‘ .!%$&&$$%$;`:‘ `!%%%%:.... ....:$&$$$%$$%%$$$$$%$$%$&$%%%%;
.. .;%$&&&$%|:. ...;%|‘..........‘|$%%%$$%%$$&&$%$$%%%$%%%$;
;$$&&&$%!` .`....‘`.... ......`!%%%$$%%$&&&$$&&$!!$%%%$:
‘%$&&&&$!`. .`........``.......`!%%$$$%$&&&&$$&&$;;$%%%%‘
‘|$&&&&!``..```. ........`|@@|‘....`:|%%$$%%$&&&&$$&&$‘:$%%%|`
`|$&&&&$‘ .``````‘‘‘::`..........``.:%%$&$%|‘`!&&$$&&%‘:%%%%;.
;$$&&|;!:`........... .‘:`....`````!%$&&$%|;‘;&&&%|%%‘;%%%%:
‘%$&$: ...................`‘‘`...`:%%$&$$!`..!&&&$;`:;|%%%!`
;$&&%:..................... .‘:``!%$&&$;...:$&%‘`;‘ ;%%%%:
.;$&&&$:..........`‘............`!%$&&&;..‘%&&! `!%%%:
.‘:|&&&|‘‘`.............. ...‘|$&&$||$&&&|` :|‘``
.!%: `|$%|!:‘`.........`:!%$&&&&&$;‘‘. `.
.:!%$%||||||%%$$$$$$$$$%$%%$$$%%:.
`!%$%%%%%%%|||||||||||%|||||||%%%%%$%%%%|:
‘%%%%%%%%%%%%||||||||!!|||||||||||%$$%%%%%%%%$%:
:%$$$%%%$%$$%||||||||!;%%||||||||%%%%%%%%%%%%%%%%|‘
.;$%%%%$$$$$%%|||||%$$$$$%||||||||%$$%%%%%%%%%%%%%%‘
.!%%%%%%$$%%$%%|||||;;%||||||||%$$&&|!%$$%%%$$$$$%;.
.!%%%%%%%%%%%%%%$%||%%%%%%%%%%%$&$$;`;%%%%%%%%$$!.
:%%%%%%%%%%%%%%||%%%%%%%%%%%$$$%%%%%%%%%%%%%|‘
:%%%%%%%%%%$$%%%%%%%%%%%%%%%;`;%%%%%%%|:
.;%%%%%%%%%%%%%%%%%%%%%%%%%%%:..:|%%%!.
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|;:`
;$%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%‘
`|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;
.:!%$%%%%%%%%%%%%%%%%%%%%%%%%%%%%$!.
;!‘;%%%%%%%%%%%%%%%%%%%%%!:`. `|$%‘
.;%%%%%%%%%%%||%%%%%%%%%|:‘;|%$%%%%%;.
.!%%%%%%%%%%%%$$%%%%%%%%%%%%%%%%%%%%%‘
.!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;.
.;%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%‘
;%$$%%%%%%%%$$$$%%%%%%%%%%%%%%%%%%%%%‘
`|$&$%%%%%%$%$$$%%%%%%%%%%%%$%%%%%$&%%!`
:%$&$%%||%%%%$$%%%$%%%%%$$!:|%||%%$&$%%!`
**/
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#else
#include <algortmphm>
#include <btmpset>
#include <cmath>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
#endif
using namespace std;
#define inf __INT_MAX__
#define enf INT_MIN
#define INF LLONG_MAX
#define ENF LLONG_MIN
const int MAXN = 100 + 10;
const double pi = acos(-1.0);
const double eps = 1e-7;
typedef long long ll;
typedef unsigned long long ull;
#define zhengfu(x) ((x > eps) - (x < -eps))
#define Dprint(...) printf("%.10f\n", ##__VA_ARGS__)
#define Iprint(...) printf("%d\n", ##__VA_ARGS__)
char s[MAXN][MAXN], s2[MAXN][MAXN];
bool vis[MAXN][MAXN];
vector<pair<pair<int, int>, pair<int, int>>> v;
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, 1, -1};
struct vec {
int x, y, f, p;
};
int n;
void bfs(int x, int y) {
memset(vis, 0, sizeof(vis));
queue<vec> q;
q.push(vec{x, y, 0, -1});
bool flag = vis[x][y] = 1;
while (!q.empty() && flag) {
vec tmp = q.front();
q.pop();
for (int i = 0, ix, iy; i < 4; i++) {
ix = tmp.x + dx[i], iy = tmp.y + dy[i];
if (ix >= 0 && ix <= n + 1 && iy >= 0 && iy <= n + 1 && !vis[ix][iy])
if (s2[ix][iy] == 0) {
vis[ix][iy] = 1;
if (i == tmp.p)
q.push(vec{ix, iy, tmp.f, tmp.p});
else if (tmp.f < 3)
q.push(vec{ix, iy, tmp.f + 1, i});
} else if (s2[ix][iy] == s2[x][y])
if (tmp.f + (i != tmp.p) <= 3) {
v.push_back(make_pair(make_pair(x, y), make_pair(ix, iy)));
s2[x][y] = s2[ix][iy] = flag = 0;
break;
}
}
}
}
bool solve(int x, int y) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
s2[i][j] = s[i][j];
v.clear();
while (1) {
int lpos = v.size();
for (int i = y; i <= n; i++)
if (s2[x][i])
bfs(x, i);
for (int i = x + 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (s2[i][j])
bfs(i, j);
for (int i = 1; i < x; i++)
for (int j = 1; j <= n; j++)
if (s2[i][j])
bfs(i, j);
for (int i = 1; i < y; i++)
if (s2[x][i])
bfs(x, i);
if (lpos == v.size())
break;
}
if (v.size() * 2 == n * n) {
cout << "YES" << endl;
for (auto it : v)
printf("%d %d %d %d\n", it.first.first, it.first.second, it.second.first, it.second.second);
return 1;
} else
return 0;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%s", s[i] + 1);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (s[i][j])
if (solve(i, j))
exit(0);
cout << "NO" << endl;
}
``
/**
爆ぜろリアル!弾けろシナプス!パニッシュメント?ディス?ワールド!
‘;!!!:`
.;%%%%$$$$%%%;.
.;$%;. :%;.
`||` :!.
.!: ::
:; .`.
‘` ..
`` .
.. ..
..
`;||!:‘;|%$$$%%%$$%|;‘.
‘|%%%%%%%%%%%%%%%%%%%%%%%%%%%%|:.
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$|:
.:!%%%%%%%%%%|!|%%%%$$&$$$%%%%%%%%%%%%%%%%|‘ `:‘.
‘!|%%%%%||%%%%%%%%%%%$&&&$%%%%%$$$%%%%%%%%%%%|‘‘:‘:‘.
`|%%%%%%%%%%%%%$%%%%%%%$&&&&$$%%%$$$%%%%%%%%%%%%|;:::‘::‘:`
:%%%%%%$$%%%$$%%$%%%%%%%$&&&&&$$%%|%$%%%|!|%%%%%$!‘::::;|!:‘.
.;$%%%%%$$%%%$$%%$%%%%%%%%$&&&&&$$$%%$$$%%%!!%$%%%%!::!%%%%|;‘.
.;%$%%%$$$%%%$$%%||%$$%%%%$$&&&&&&$$%%$$%%%%%%%$&&&$%$$$$%%%%|:.
;%%%%%$$$%%$&$%%!:!$$$%%%%$&$||&&&&$$%$$$%%%%%%$$$%%%%$$$$%%%|‘
:%%$%%$$$$%$&&$%!`‘|$&$%%%%$&|`.!&&&&$%$$$%%%%%%%$%%%%%%$$$$%%%;
`!%|%%%$&$%%$&$$|‘.‘|&&$%%%%$%|!‘.:$&&&$$$$%%%%%%%%%%%%%%$$$$%%%|`
;%‘:%%$&&$%$&|!|‘.`:|&&$%%%$$|‘‘‘``‘%&&&$$$%%%%%%%%%%%%%%$&&$%%%%:
`;‘ ;%%$&$%%$%;;: .:!%$%%%$|` .. .!&&&$$$%%$%%%$%$$%$$%$&$%%%$;
‘‘ .!%$&&$$%$;`:‘ `!%%%%:.... ....:$&$$$%$$%%$$$$$%$$%$&$%%%%;
.. .;%$&&&$%|:. ...;%|‘..........‘|$%%%$$%%$$&&$%$$%%%$%%%$;
;$$&&&$%!` .`....‘`.... ......`!%%%$$%%$&&&$$&&$!!$%%%$:
‘%$&&&&$!`. .`........``.......`!%%$$$%$&&&&$$&&$;;$%%%%‘
‘|$&&&&!``..```. ........`|@@|‘....`:|%%$$%%$&&&&$$&&$‘:$%%%|`
`|$&&&&$‘ .``````‘‘‘::`..........``.:%%$&$%|‘`!&&$$&&%‘:%%%%;.
;$$&&|;!:`........... .‘:`....`````!%$&&$%|;‘;&&&%|%%‘;%%%%:
‘%$&$: ...................`‘‘`...`:%%$&$$!`..!&&&$;`:;|%%%!`
;$&&%:..................... .‘:``!%$&&$;...:$&%‘`;‘ ;%%%%:
.;$&&&$:..........`‘............`!%$&&&;..‘%&&! `!%%%:
.‘:|&&&|‘‘`.............. ...‘|$&&$||$&&&|` :|‘``
.!%: `|$%|!:‘`.........`:!%$&&&&&$;‘‘. `.
.:!%$%||||||%%$$$$$$$$$%$%%$$$%%:.
`!%$%%%%%%%|||||||||||%|||||||%%%%%$%%%%|:
‘%%%%%%%%%%%%||||||||!!|||||||||||%$$%%%%%%%%$%:
:%$$$%%%$%$$%||||||||!;%%||||||||%%%%%%%%%%%%%%%%|‘
.;$%%%%$$$$$%%|||||%$$$$$%||||||||%$$%%%%%%%%%%%%%%‘
.!%%%%%%$$%%$%%|||||;;%||||||||%$$&&|!%$$%%%$$$$$%;.
.!%%%%%%%%%%%%%%$%||%%%%%%%%%%%$&$$;`;%%%%%%%%$$!.
:%%%%%%%%%%%%%%||%%%%%%%%%%%$$$%%%%%%%%%%%%%|‘
:%%%%%%%%%%$$%%%%%%%%%%%%%%%;`;%%%%%%%|:
.;%%%%%%%%%%%%%%%%%%%%%%%%%%%:..:|%%%!.
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|;:`
;$%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%‘
`|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;
.:!%$%%%%%%%%%%%%%%%%%%%%%%%%%%%%$!.
;!‘;%%%%%%%%%%%%%%%%%%%%%!:`. `|$%‘
.;%%%%%%%%%%%||%%%%%%%%%|:‘;|%$%%%%%;.
.!%%%%%%%%%%%%$$%%%%%%%%%%%%%%%%%%%%%‘
.!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;.
.;%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%‘
;%$$%%%%%%%%$$$$%%%%%%%%%%%%%%%%%%%%%‘
`|$&$%%%%%%$%$$$%%%%%%%%%%%%$%%%%%$&%%!`
:%$&$%%||%%%%$$%%%$%%%%%$$!:|%||%%$&$%%!`
**/
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#else
#include <algortmphm>
#include <btmpset>
#include <cmath>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
#endif
using namespace std;
#define inf __INT_MAX__
#define enf INT_MIN
#define INF LLONG_MAX
#define ENF LLONG_MIN
const int MAXN = 1e5 + 10;
const double pi = acos(-1.0);
const double eps = 1e-7;
typedef long long ll;
typedef unsigned long long ull;
#define zhengfu(x) ((x > eps) - (x < -eps))
#define Dprint(...) printf("%.10f\n", ##__VA_ARGS__)
#define Iprint(...) printf("%d\n", ##__VA_ARGS__)
double f2(int x) {
return x * pow(log(x), 3) / 12.0 - x / 3.0 + 0.25 + 0.25 * exp(2) - x * pow(log(x), 2) * 0.25 + 0.5 * x * log(x) - 0.5 * x;
}
double sum(int x) {
return f2(x);
}
double dp[8];
int main() {
int t;
cin >> t;
for (int i = 1; i <= 7; i++)
dp[i] = dp[i - 1] + sum(i);
Dprint(dp[7] + sum(8));
while (t--) {
int n;
scanf("%d", &n);
double ans = 0;
if (n >= 8)
ans = dp[7] + (n - 8 + 1) * ((1 - exp(2)) * 0.25 + (n + 8) / 6.0);
else
ans = dp[n];
Dprint(ans);
}
}
double fun(double x) //原积分函数
{
return x;
}
double simpson(double l, double r) //辛普森法则
{
double mid = (l + r) / 2.0;
return (fun(l) + fun(r) + 4.0 * fun(mid)) * (r - l) / 6.0;
}
double asr(double l, double r, double eps, double ans) {//自适应自动控制区间分割的大小
double mid = (l + r) / 2;
double l_ = simpson(l, mid), r_ = simpson(mid, r);
if (fabs(l_ + r_ - ans) <= 15 * eps)
return l_ + r_ + (l_ + r_ - ans) / 15;
return asr(l, mid, eps / 2, l_) + asr(mid, r, eps / 2, r_);
}
inline double _asr(double l, double r, double eps) {//函数进入口
return asr(l, r, eps, simpson(l, r));
}
\(有了板子,我们就可以直接往里套了,把模板改一改就是答案了\)
/**
爆ぜろリアル!弾けろシナプス!パニッシュメント?ディス?ワールド!
‘;!!!:`
.;%%%%$$$$%%%;.
.;$%;. :%;.
`||` :!.
.!: ::
:; .`.
‘` ..
`` .
.. ..
..
`;||!:‘;|%$$$%%%$$%|;‘.
‘|%%%%%%%%%%%%%%%%%%%%%%%%%%%%|:.
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$|:
.:!%%%%%%%%%%|!|%%%%$$&$$$%%%%%%%%%%%%%%%%|‘ `:‘.
‘!|%%%%%||%%%%%%%%%%%$&&&$%%%%%$$$%%%%%%%%%%%|‘‘:‘:‘.
`|%%%%%%%%%%%%%$%%%%%%%$&&&&$$%%%$$$%%%%%%%%%%%%|;:::‘::‘:`
:%%%%%%$$%%%$$%%$%%%%%%%$&&&&&$$%%|%$%%%|!|%%%%%$!‘::::;|!:‘.
.;$%%%%%$$%%%$$%%$%%%%%%%%$&&&&&$$$%%$$$%%%!!%$%%%%!::!%%%%|;‘.
.;%$%%%$$$%%%$$%%||%$$%%%%$$&&&&&&$$%%$$%%%%%%%$&&&$%$$$$%%%%|:.
;%%%%%$$$%%$&$%%!:!$$$%%%%$&$||&&&&$$%$$$%%%%%%$$$%%%%$$$$%%%|‘
:%%$%%$$$$%$&&$%!`‘|$&$%%%%$&|`.!&&&&$%$$$%%%%%%%$%%%%%%$$$$%%%;
`!%|%%%$&$%%$&$$|‘.‘|&&$%%%%$%|!‘.:$&&&$$$$%%%%%%%%%%%%%%$$$$%%%|`
;%‘:%%$&&$%$&|!|‘.`:|&&$%%%$$|‘‘‘``‘%&&&$$$%%%%%%%%%%%%%%$&&$%%%%:
`;‘ ;%%$&$%%$%;;: .:!%$%%%$|` .. .!&&&$$$%%$%%%$%$$%$$%$&$%%%$;
‘‘ .!%$&&$$%$;`:‘ `!%%%%:.... ....:$&$$$%$$%%$$$$$%$$%$&$%%%%;
.. .;%$&&&$%|:. ...;%|‘..........‘|$%%%$$%%$$&&$%$$%%%$%%%$;
;$$&&&$%!` .`....‘`.... ......`!%%%$$%%$&&&$$&&$!!$%%%$:
‘%$&&&&$!`. .`........``.......`!%%$$$%$&&&&$$&&$;;$%%%%‘
‘|$&&&&!``..```. ........`|@@|‘....`:|%%$$%%$&&&&$$&&$‘:$%%%|`
`|$&&&&$‘ .``````‘‘‘::`..........``.:%%$&$%|‘`!&&$$&&%‘:%%%%;.
;$$&&|;!:`........... .‘:`....`````!%$&&$%|;‘;&&&%|%%‘;%%%%:
‘%$&$: ...................`‘‘`...`:%%$&$$!`..!&&&$;`:;|%%%!`
;$&&%:..................... .‘:``!%$&&$;...:$&%‘`;‘ ;%%%%:
.;$&&&$:..........`‘............`!%$&&&;..‘%&&! `!%%%:
.‘:|&&&|‘‘`.............. ...‘|$&&$||$&&&|` :|‘``
.!%: `|$%|!:‘`.........`:!%$&&&&&$;‘‘. `.
.:!%$%||||||%%$$$$$$$$$%$%%$$$%%:.
`!%$%%%%%%%|||||||||||%|||||||%%%%%$%%%%|:
‘%%%%%%%%%%%%||||||||!!|||||||||||%$$%%%%%%%%$%:
:%$$$%%%$%$$%||||||||!;%%||||||||%%%%%%%%%%%%%%%%|‘
.;$%%%%$$$$$%%|||||%$$$$$%||||||||%$$%%%%%%%%%%%%%%‘
.!%%%%%%$$%%$%%|||||;;%||||||||%$$&&|!%$$%%%$$$$$%;.
.!%%%%%%%%%%%%%%$%||%%%%%%%%%%%$&$$;`;%%%%%%%%$$!.
:%%%%%%%%%%%%%%||%%%%%%%%%%%$$$%%%%%%%%%%%%%|‘
:%%%%%%%%%%$$%%%%%%%%%%%%%%%;`;%%%%%%%|:
.;%%%%%%%%%%%%%%%%%%%%%%%%%%%:..:|%%%!.
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|;:`
;$%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%‘
`|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;
.:!%$%%%%%%%%%%%%%%%%%%%%%%%%%%%%$!.
;!‘;%%%%%%%%%%%%%%%%%%%%%!:`. `|$%‘
.;%%%%%%%%%%%||%%%%%%%%%|:‘;|%$%%%%%;.
.!%%%%%%%%%%%%$$%%%%%%%%%%%%%%%%%%%%%‘
.!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;.
.;%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%‘
;%$$%%%%%%%%$$$$%%%%%%%%%%%%%%%%%%%%%‘
`|$&$%%%%%%$%$$$%%%%%%%%%%%%$%%%%%$&%%!`
:%$&$%%||%%%%$$%%%$%%%%%$$!:|%||%%$&$%%!`
**/
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#else
#include <algortmphm>
#include <btmpset>
#include <cmath>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
#endif
using namespace std;
#define inf __INT_MAX__
#define enf INT_MIN
#define INF LLONG_MAX
#define ENF LLONG_MIN
const int MAXN = 1e5 + 10;
const double pi = acos(-1.0);
const double eps = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
#define zhengfu(x) ((x > eps) - (x < -eps))
#define Dprint(...) printf("%.10f\n", ##__VA_ARGS__)
#define Iprint(...) printf("%d\n", ##__VA_ARGS__)
/**
* 以下
* 皆为
* 辛普森函数
* */
double fun(double t, double x) //原积分函数
{
return t * t * fabs(exp(t + t) - x);
}
double simpson(double l, double r, double x) //辛普森法则
{
double mid = (l + r) / 2.0;
return (fun(l, x) + fun(r, x) + 4.0 * fun(mid, x)) * (r - l) / 6.0;
}
double asr(double l, double r, double eps, double ans, double x) {
double mid = (l + r) / 2;
double l_ = simpson(l, mid, x), r_ = simpson(mid, r, x);
if (fabs(l_ + r_ - ans) <= 15 * eps)
return l_ + r_ + (l_ + r_ - ans) / 15;
return asr(l, mid, eps / 2, l_, x) + asr(mid, r, eps / 2, r_, x);
}
inline double _asr(double l, double r, double eps, double x) {
return asr(l, r, eps, simpson(l, r, x), x);
}
double dp[8];
int main() {
int t;
cin >> t;
// dp[1] = -1.0 / 3.0 + exp(2) * 0.25 - 0.25;
for (int i = 1; i <= 7; i++)
dp[i] = dp[i - 1] + _asr(0, 1, eps, i);
while (t--) {
int n;
// cin >> n;
scanf("%d", &n);
double ans = 0;
if (n >= 8)
ans = dp[7] + (n - 8 + 1) * ((1 - exp(2)) * 0.25 + (n + 8) / 6.0);
else
ans = dp[n];
Dprint(ans);
}
}
标签:ima rac sig mamicode tor 添加 自动 法则 tac
原文地址:https://www.cnblogs.com/CrossAutomaton/p/14390028.html