mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-07-07 18:06:58 +08:00
Upload codes: contests
This commit is contained in:
58
Luogu/P_1015_NOIP_1999_普及组_回文数.cpp
Normal file
58
Luogu/P_1015_NOIP_1999_普及组_回文数.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#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;
|
||||
|
||||
char s[M];
|
||||
int a[M], top;
|
||||
bool check()
|
||||
{
|
||||
int t = top / 2;
|
||||
for (int i = 0; i <= t; ++i)
|
||||
if (a[i] != a[top - i])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
cout.tie(0);
|
||||
int n, step = 0;
|
||||
cin >> n >> s;
|
||||
top = strlen(s) - 1;
|
||||
for (int i = 0; i <= top; ++i)
|
||||
if (s[i] >= '0' && s[i] <= '9')
|
||||
a[top - i] = s[i] - '0';
|
||||
else
|
||||
a[top - i] = s[i] - 55;
|
||||
while (check()) {
|
||||
if (step > 30) {
|
||||
cout << "Impossible!";
|
||||
return 0;
|
||||
}
|
||||
for (int i = 0; i <= top; ++i)
|
||||
if (top - i >= i)
|
||||
a[i] += a[top - i];
|
||||
else
|
||||
a[i] = a[top - i];
|
||||
for (int i = 0; i <= top; ++i)
|
||||
if (a[i] >= n)
|
||||
a[i + 1]++, a[i] -= n;
|
||||
if (a[top + 1])
|
||||
top++;
|
||||
step++;
|
||||
}
|
||||
cout << "STEP=" << step;
|
||||
return 0;
|
||||
}
|
34
Luogu/P_10446_64_位整数乘法.cpp
Normal file
34
Luogu/P_10446_64_位整数乘法.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
lo qpow(lo a, lo b, lo p) {
|
||||
lo result = 0;
|
||||
while (b) {
|
||||
if (b & 1) {
|
||||
result += a;
|
||||
result %= p;
|
||||
}
|
||||
b >>= 1;
|
||||
a += a;
|
||||
a %= p;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
lo a, b, p;
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> a >> b >> p;
|
||||
cout << qpow(a, b, p);
|
||||
return 0;
|
||||
}
|
27
Luogu/P_1060_NOIP_2006_普及组_开心的金明.cpp
Normal file
27
Luogu/P_1060_NOIP_2006_普及组_开心的金明.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
<2025/1/21>
|
||||
*/
|
||||
|
||||
int m, n, d[N], w, v;
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> m >> n;
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cin >> v >> w;
|
||||
for(int j = m; j >= v; j--){
|
||||
d[j] = max(d[j], d[j - v] + w * v);
|
||||
}
|
||||
}
|
||||
printf("%d",d[m]);
|
||||
return 0;
|
||||
}
|
49
Luogu/P_1135_奇怪的电梯.cpp
Normal file
49
Luogu/P_1135_奇怪的电梯.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#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, k;
|
||||
int a[N];
|
||||
int ans=0;
|
||||
|
||||
bool isPrime(int x)
|
||||
{
|
||||
if (x == 1)
|
||||
return false;
|
||||
for (int i = 2; i * i <= x; i++)
|
||||
if (x % i == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void dfs(int x, int sum, int cnt)
|
||||
{
|
||||
if (x == k) {
|
||||
if (isPrime(sum))
|
||||
ans++;
|
||||
return;
|
||||
}
|
||||
for (int i = cnt; i < n; i++) {
|
||||
dfs(x + 1, sum + a[i], i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i];
|
||||
dfs(0, 0, 0);
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}`
|
Reference in New Issue
Block a user