upload some new code

This commit is contained in:
Frederick Chen 2024-12-28 14:11:21 +08:00
parent b64d31db74
commit 394e431a4a
22 changed files with 1236 additions and 0 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -0,0 +1,53 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int f[N], far[N], a[N], flag[N], p, s, t, n;
signed main()
{
cin >> p;
cin >> s >> t >> n;
if (s == t) {
int cont = 0, q;
for (int i = 1; i <= n; i++) {
cin >> q;
cont += ((q % s) == 0);
}
cout << cont;
return 0;
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + 1 + n);
a[0] = 0;
f[0] = 0;
far[n + 1] = min(int(p - a[n]), 100);
p = 0;
for (int i = 1; i <= n; i++) {
far[i] = min(a[i] - a[i - 1], 90);
p += far[i], flag[p] = 1;
}
p += far[n + 1];
for (int i = 1; i <= p + 9; i++) {
f[i] = IMX - 1;
for (int j = s; j <= t; j++) {
if(i >= j) f[i] = min(f[i], f[i - j] + flag[i]);
}
}
int mn = INT_MAX - 1;
for (int i = p; i <= p + 9; i++) mn = min(mn, f[i]);
cout << mn;
return 0;
}

View File

@ -0,0 +1,62 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int fa[N], dep[N], size[N], son[N], top[N], id[N], rev[N];
int fir[N];
struct edge {
int to, nex;
} arr[N];
void dfs1(int u, int dad)
{
size[u] - 1;
fa[u] = dad;
dep[u] = dep[dad] + 1;
for (int i = fir[u]; i != -1; i = arr[i].nex) {
int v = arr[i].to;
if (v == dad) continue;
dfs1(v, u);
size[u] += size[v];
if (size[v] > size[son[u]]) son[u] = v;
}
}
void dfs2(int u) {
if (son[u]) {
int v = son[u];
id[v]++;
top[v] = top[u];
rev[t] = v;
dfs2(v);
}
for (int i = fir[u]; i != -1; i = arr[i].nex);
{
int v = arr[i].to;
if (!top[v]) {
id[v] = ++t;
top[v] = v;
rev[t] = v;
dfs2(v, u);
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
return 0;
}

View File

@ -0,0 +1,78 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int n, m;
int sum = 0;
struct node
{
int mat[4][4];
};
node z;
node matrix_nul(node x, node y)
{
memset(z.mat, 0, sizeof(z.mat));
for(int i = 1; i <= 3; i ++ )
{
for(int j = 1; j <= 3; j ++ )
{
for(int k = 1; k <= 3; k ++ )
{
z.mat[i][j] += (x.mat[i][k]) % m * (y.mat[k][j]) % m;
z.mat[i][j] %= m;
}
}
}
return z;
}
node matrix_pow(int k)
{
node t, a;
t.mat[1][1] = 1;
t.mat[1][2] = 1;
t.mat[1][3] = 1;
a.mat[1][1]=1;
a.mat[1][2]=0;
a.mat[1][3]=0;
a.mat[2][1]=1;
a.mat[2][2]=1;
a.mat[2][3]=1;
a.mat[3][1]=0;
a.mat[3][2]=1;
a.mat[3][3]=0;
while(k)
{
if(k % 2 == 1) t = matrix_nul(t, a);
k /= 2;
a = matrix_nul(a, a);
}
return t;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m ;
node temp;
temp = matrix_pow(n - 1);
int ans = temp.mat[1][1] * 1 + temp.mat[2][1] * 0;
ans %= m;
cout << ans % m ;
return 0;
}

61
FZOI/Tad的小蛋糕.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
int n, m;
int a[1000000];
int qzh[1000000];
int st[1000000][25];
int lg[1000000];
void init()
{
lg[1] = 0;
for (int i = 2; i <= n; i++)
{
lg[i] = lg[i / 2] + 1;
}
for (int i = 1; i <= n; i++)
{
st[i][0] = qzh[i];
}
for (int k = 1; k <= lg[m]; k++)
{
for (int i = 1; i <= n; i++)
{
st[i][k] = max(st[i][k - 1], st[min(i + (1 << (k - 1)), n)][k - 1]);
}
}
} // ST表模板 -> 初始化
int quary(int l, int r)
{
int k = lg[r - l + 1];
return max(st[l][k], st[r - (1 << k) + 1][k]);
} // ST表模板 -> 求最大
signed main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
qzh[i] = qzh[i - 1] + a[i];
}
int maxl = -INT_MIN;
init();
for (int i = 1; i <= n; i++)
{
int r = min(i + m - 1, n);
int s = quary(i, r) - qzh[i - 1];
maxl = max(maxl, s);
}
cout << maxl;
return 0;
}

View File

@ -0,0 +1,35 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int n;
int a[N], cnt[N];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
int hui = 0, ans = 0;
for (int i = N - 1; i >= 1; i--) {
ans += min(cnt[i], hui);
hui = max(hui, cnt[i]);
}
cout << n - ans;
return 0;
}

View File

@ -0,0 +1,133 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
int n, m;
char a[55][55];
int fx[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
struct node
{
int x;
int y;
int cnt;
};
int water[55][55];
bool h_used[55][55];
queue<node> Water;
node startt, endd;
queue<node> Q;
node X[2505];
int xid;
void Water_Bfs()
{
while (!Water.empty())
{
node noww = Water.front();
Water.pop();
noww.cnt++;
for (int i = 0; i < 4; i++)
{
node _next = noww;
_next.x += fx[i][0], _next.y += fx[i][1];
if (_next.x < 1 || _next.y < 1 || _next.x > n || _next.y > m)
continue;
if (h_used[_next.x][_next.y])
continue;
water[_next.x][_next.y] = min(water[_next.x][_next.y], _next.cnt);
Water.push(_next);
h_used[_next.x][_next.y] = 1;
}
}
}
void Ans_Bfs()
{
Q.push(startt);
while (!Q.empty())
{
node noww = Q.front();
Q.pop();
if (water[noww.x][noww.y] <= noww.cnt)
continue;
if (noww.x == endd.x && noww.y == endd.y)
{
cout << noww.cnt;
return;
}
noww.cnt++;
for (int i = 0; i < 4; i++)
{
node _next = noww;
_next.x += fx[i][0], _next.y += fx[i][1];
if (_next.x < 1 || _next.y < 1 || _next.x > n || _next.y > m)
continue;
if (h_used[_next.x][_next.y])
continue;
if (a[_next.x][_next.y] == 'X')
continue;
Q.push(_next);
h_used[_next.x][_next.y] = 1;
}
}
cout << "KAKTUS";
}
signed main()
{
memset(water, 127, sizeof(water));
cin >> n >> m;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
cin >> a[i][j];
if (a[i][j] == 'S')
{
startt.x = i;
startt.y = j;
startt.cnt = 0;
}
if (a[i][j] == 'D')
{
endd.x = i;
endd.y = j;
}
if (a[i][j] == 'X')
{
X[xid].x = i;
X[xid++].y = j;
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (a[i][j] == '*')
{
node w;
w.x = i;
w.y = j;
w.cnt = 0;
Water.push(w);
water[i][j] = 0;
memset(h_used, 0, sizeof(h_used));
h_used[endd.x][endd.y] = 1;
for (int k = 0; k < xid; k++)
{
h_used[X[k].x][X[k].y] = 1;
}
Water_Bfs();
}
}
}
water[endd.x][endd.y] = 1e8;
memset(h_used, 0, sizeof(h_used));
h_used[startt.x][startt.y] = 1;
Ans_Bfs();
}

View File

@ -0,0 +1,55 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int n;
long long now = 1;
bool a[N];
signed main()
{
scanf("%d", &n);
if (n % 2 != 0)
{
printf("-1");
return 0;
}
int i = 0;
while (now * 2 <= n)
{
now *= 2;
i++;
}
int i1 = i;
while (now > 1)
{
if (n - now >= 0)
{
a[i1] = 1;
n -= now;
}
i1--;
now /= 2;
}
for (int j = i; j >= 1; --j)
{
if (a[j] == 0)
continue;
long long ans = pow(2, j);
printf("%lld ", ans);
}
return 0;
}

View File

@ -0,0 +1,57 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
int n, m;
int a[100050], dpmax[50005][22], dpmin[50005][21];
int LOG[50005];
void build()
{
LOG[0] = -1;
for (int i = 1; i <= 50005; i++)
LOG[i] = LOG[i >> 1] + 1;
for (int i = 1; i <= n; i++)
{
dpmin[i][0] = dpmax[i][0] = a[i];
}
int p = log2(n);
for (int k = 1; k <= p; k++)
{
for (int s = 1; s + (1 << k) <= n + 1; s++)
{
dpmax[s][k] = max(dpmax[s][k - 1], dpmax[s + (1 << (k - 1))][k - 1]);
dpmin[s][k] = min(dpmin[s][k - 1], dpmin[s + (1 << (k - 1))][k - 1]);
}
}
}
int query(int l, int r)
{
int k = LOG[r - l + 1];
int x = max(dpmax[l][k], dpmax[r - (1 << k) + 1][k]);
int y = min(dpmin[l][k], dpmin[r - (1 << k) + 1][k]);
return x - y;
}
signed main()
{
"toothless. #17";
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
build();
for (int i = 1; i <= m; i++)
{
int l, r;
cin >> l >> r;
cout << query(l, r) << endl;
}
return 0;
}

View File

@ -0,0 +1,50 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int n;
double a[M][M];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n + 1; j++) cin >> a[i][j];
}
for (int i = 1; i <= n; i++) {
int flag = 1;
for (int j = i; j <= n; j++)
{
if (fabs(a[j][i]) > 1e-8) {
flag = 0;
for (int k = 1; k <= n + 1; k ++ ) swap(a[i][k], a[j][k]);
break;
}
}
if (flag) {
cout << "No Solution" << endl ;
return 0;
}
for (int j = 1; j <= n; j++) {
if (i != j) {
double rate = a[j][i] / a[i][i];
for (int k = i; k <= n + 1; k++) a[j][k] -= a[i][k] * rate;
}
}
}
for (int i = 1; i <= n; i++) printf("%.2lf\n", a[i][n + 1] / a[i][i]);
return 0;
}

75
FZOI/分组(groping).cpp Normal file
View File

@ -0,0 +1,75 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
// 判定函数给定组的最小人数为x判断是否可以分组
bool canGroup(const vector<int>& a, int x) {
int n = a.size();
int count = 0; // 记录已经分成的组数量
int group_size = 1; // 当前组的队员人数
for (int i = 1; i < n; i++) {
if (a[i] == a[i - 1] + 1) {
// 实力值连续,当前组人数增加
group_size++;
} else {
// 实力值不连续,组结束
if (group_size >= x) {
count++; // 记录一个符合条件的组
}
group_size = 1; // 开始新组
}
}
// 更新最后一组的判断
if (group_size >= x) {
count++;
}
// 如果我们可以将所有人分成符合条件的组返回true
return count * x <= n;
}
signed main()
{
"toothless. #17";
int n;
cin >> n; // 读取队员数量
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i]; // 读取每个队员的实力值
}
// 对实力值进行排序
sort(a.begin(), a.end());
// 使用二分查找最小组人数的最大值
int left = 1, right = n;
int ans = 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (canGroup(a, mid)) {
// 如果可以分组,尝试更大的值
ans = mid;
left = mid + 1;
} else {
// 否则尝试更小的值
right = mid - 1;
}
}
// 输出最小的组人数的最大值
cout << ans << endl;
return 0;
}

51
FZOI/区间最大值.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
int n, m;
int a[100050], dpmax[100050][100];
int LOG[500005];
void build()
{
LOG[0] = -1;
for (int i = 1; i <= 500005; i++)
LOG[i] = LOG[i >> 1] + 1;
for (int i = 1; i <= n; i++) {
dpmax[i][0] = a[i];
}
int p = log2(n);
for (int k = 1; k <= p; k++) {
for (int s = 1; s + (1 << k) <= n + 1; s++) {
dpmax[s][k] = max(dpmax[s][k - 1], dpmax[s + (1 << (k - 1))][k - 1]);
}
}
}
int query(int l, int r)
{
int k = LOG[r - l + 1];
int x = max(dpmax[l][k], dpmax[r - (1 << k) + 1][k]);
return x;
}
signed main()
{
"toothless. #17";
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
build();
for (int i = 1; i <= m; i++) {
int l, r;
cin >> l >> r;
cout << query(l, r) << endl;
}
return 0;
}

32
FZOI/去重.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int n;
int a[N];
map<int, bool> mp;
signed main()
{
cin >> n;
for (int i = 1; i <= n; i ++ ) {
cin >> a[i];
}
for (int i = 1; i <= n; i ++ ) {
if (!mp[a[i]]) {
cout << a[i] << " ";
mp[a[i]] = true;
}
}
return 0;
}

38
FZOI/找拖后腿的.cpp Normal file
View File

@ -0,0 +1,38 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int n;
struct stu
{
int id, sc;
} name[N];
int g;
signed main()
{
cin >> n;
for (int i = 1; i <= n; i++) {
name[i].id = i;
cin >> name[i].sc;
g += name[i].sc;
}
g /= n;
for (int i = 1; i <= n; i++) {
if(name[i].sc < g) cout << name[i].id << " ";
}
return 0;
}

32
FZOI/插入.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int n;
int a[N];
int m;
signed main()
{
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
cin >> m;
a[n + 1] = m;
sort(a + 1, a + n + 2);
for (int i = 1; i <= n + 1; i++) {
cout << a[i] << " ";
}
return 0;
}

View File

@ -0,0 +1,111 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if (dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
string s;
int len, last, pre, x, flag, cs;
char ch;
vector<string> lstr, rstr;
bool iszf(char ch)
{
return ch == '+' || ch == '-' || ch == '*' || ch == '/';
}
bool is_num(char s)
{
return s >= '0' && s <= '9';
}
bool is_str(const std::string &s)
{
char *endptr;
strtod(s.c_str(), &endptr);
return !(*endptr == '\0');
}
int renum(string s)
{
string t = s.substr(0, s.size());
return stoi(t);
}
void print()
{
int ll = lstr.size();
for (int i = 0; i < ll; i ++ )
cout << lstr[i] << ' ';
cout << endl ;
ll = rstr.size();
for (int i = 0; i < ll; i ++ )
cout << rstr[i] << ' ';
cout << endl ;
}
bool is_ch(char ch)
{
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
}
signed main()
{
ch = ' ';
getline(cin, s);
len = s.size();
for (int i = 0; i < s.size(); i++)
{
if (!(is_num(s[i])) && !iszf(s[i]) && is_ch(s[i]))
ch = s[i];
if (s[i] == '=')
{
flag = 1;
lstr.push_back(s.substr(last, i - last));
last = i + 1;
pre = i;
}
if (iszf(s[i]))
{
string wxh = s.substr(last, i - last);
if (wxh.size() == 1 && is_str(wxh))
{
wxh.insert(0, "1");
}
if (!flag)
lstr.push_back(wxh);
else
rstr.push_back(wxh);
last = i;
}
}
string wty = s.substr(last, s.size() - last);
if (wty.size() == 1 && is_str(wty))
wty.insert(0, "1");
rstr.push_back(wty);
int l = lstr.size();
for (int i = 0; i < l; i ++ )
{
if (!is_str(lstr[i]))
cs += stod(lstr[i]);
else
x -= renum(lstr[i]);
}
l = rstr.size();
for (int i = 0; i < l; i ++ )
{
if (!is_str(rstr[i]))
cs -= stod(rstr[i]);
else
x += renum(rstr[i]);
}
double cnt = cs * 1.0 / (x == 0 ? 1 : x);
printf("%c=%.3lf", ch, cnt);
return 0;
}

35
FZOI/纪念品分组.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int w, ans = 0;
int n, a[N];
int l, r;
signed main()
{
cin >> w >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
l = 1;
r = n;
while (l <= r) {
if (a[l] + a[r] <= w) {
l++, r--, ans++;
} else {
r--, ans++;
}
}
cout << ans;
return 0;
}

View File

@ -0,0 +1,77 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
int n, m;
int sum = 0;
struct node
{
int mat[3][3];
};
node z;
node matrix_nul(node x, node y)
{
memset(z.mat, 0, sizeof(z.mat));
for(int i = 1; i <= 2; i ++ )
{
for(int j = 1; j <= 2; j ++ )
{
for(int k = 1; k <= 2; k ++ )
{
z.mat[i][j] += (x.mat[i][k]) * (y.mat[k][j]);
z.mat[i][j];
}
}
}
return z;
}
node matrix_pow(int k)
{
node t, a;
t.mat[1][1] = 1;
t.mat[1][2] = 0;
t.mat[2][1] = 0;
t.mat[2][2] = 1;
a.mat[1][1] = 1;
a.mat[1][2] = 1;
a.mat[2][1] = 1;
a.mat[2][2] = 0;
while(k)
{
if(k % 2 == 1) t = matrix_nul(t, a);
k /= 2;
a = matrix_nul(a, a);
}
return t;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m ;
for(int i = 1; i <= n; i ++ )
{
node temp;
temp = matrix_pow(i - 1);
int ans = temp.mat[1][1] * 1 + temp.mat[2][1] * 0;
ans;
cout << ans << " " ;
}
return 0;
}

View File

@ -0,0 +1,57 @@
#include <iostream>
#include <cstdio>
using namespace std;
char c, a;
int f = 1, now = 1, k, b, x;
bool r;
int main()
{
while (cin >> c)
{
if (c == '-')
{
b += now * f * x;
x = 0;
f = -1;
r = 0;
}
if (c == '+')
{
b += now * f * x;
x = 0;
f = 1;
r = 0;
}
if (c == '=')
{
b += now * f * x;
x = 0;
f = 1;
now = -1;
r = 0;
}
if (c >= 'a' && c <= 'z')
{
if (r)
{
k += now * f * x;
x = 0;
}
else
k += now * f;
a = c;
r = 0;
}
if (c >= '0' && c <= '9')
{
x = x * 10 + c - '0';
r = 1;
}
}
b += now * f * x;
double ans = double(-b * 1.0 / k);
if (ans == -0.0)
ans = 0;
printf("%c=%.3lf", a, ans);
return 0;
}

61
FZOI/银行卡.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
using namespace std;
/* toothless. #17 */
int n, pre, len;
string s;
int f(int n)
{
int sum = 0;
while (n)
{
sum += n % 10;
n /= 10;
}
return sum;
}
int Get_ans(string s)
{
int cnt = 0, sum = 0;
for (int i = len - 2; i >= 0; i--)
{
++cnt;
if (cnt & 1)
sum += f((s[i] - '0') * 2);
else
sum += s[i] - '0';
}
return sum * 9 % 10;
}
signed main()
{
cin >> n >> s;
len = s.size();
for (int i = 0; i < len; i++)
{
if (s[i] == 'x')
{
pre = i;
break;
}
}
for (char i = '0'; i <= '9'; i++)
{
s[pre] = i;
int ans = Get_ans(s);
if (ans == s[len - 1] - '0')
{
cout << i;
return 0;
}
}
return 0;
}

View File

@ -0,0 +1,60 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
#define debug$ if(dev)
using namespace std;
const int N = 1e7 + 10;
const int M = 2e3 + 5;
const bool dev = false;
/* toothless. #17 */
int a[N], b[N], c[N], d[N];
int total;
int n;
void print()
{
if (total <= 2)
{
for (int k = 1; k <= n; k++)
cout << a[k] << " ";
cout << endl;
}
total++;
}
void queen(int i)
{
if (i > n)
{
print();
return;
}
else
{
for (int j = 1; j <= n; j++)
{
if ((!b[j]) && (!c[i + j]) && (!d[i - j + n]))
{
a[i] = j;
b[j] = 1;
c[i + j] = 1;
d[i - j + n] = 1;
queen(i + 1);
b[j] = 0;
c[i + j] = 0;
d[i - j + n] = 0;
}
}
}
}
signed main()
{
cin >> n;
queen(1);
cout << total;
return 0;
}

View File

@ -0,0 +1,23 @@
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
using namespace std;
/* toothless. #17 */
const int N = 1e7 + 10;
const int M = 2e3 + 5;
int a[N];
signed main()
{
int n;
cin >> n ;
for(int i = 1; i <= n; i ++ ) cin >> a[i] ;
sort(a + 1, a + 1 + n);
for(int i = 1; i <= n; i ++ ) cout << a[i] << " " ;
return 0;
}