655

yhjdsw
ifei_2
MeowRain

Li_Y_P
Bbbtt04
ProMonkey

yxc

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1010;

int n, m;
int v[N], w[N];
int f[N];

int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) cin >> v[i] >> w[i];

for (int i = 1; i <= n; i ++ )
for (int j = v[i]; j <= m; j ++ )
f[j] = max(f[j], f[j - v[i]] + w[i]);

cout << f[m] << endl;

return 0;
}



#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1010;

int n, m;
int v[N], w[N];
int f[N];

int main()
{
cin >> n >> m;

for (int i = 1; i <= n; i ++ ) cin >> v[i] >> w[i];

for (int i = 1; i <= n; i ++ )
for (int j = m; j >= v[i]; j -- )
f[j] = max(f[j], f[j - v[i]] + w[i]);

cout << f[m] << endl;

return 0;
}



#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 21, M = 1000010, MOD = 1e9;

int m;
int f[M];

int main()
{
scanf("%d", &m);
f[0] = 1;

for (int i = 1; i <= m; i *= 2)
for (int j = i; j <= m; j ++ )
f[j] = (f[j] + f[j - i]) % MOD;
printf("%d\n", f[m]);
return 0;
}



//判断输入内容有几个字符，有几个数字

# include[HTML_REMOVED]

using namespace std;

int main()
{
char c;

int nums = 0,chars = 0;
while(cin >> c)
{
if (c >= ‘0’ && c <= ‘9’) nums;
else if (c >=’A’ && c <=’z’ || c >= ‘a’ && c <=’z’ )chars
;
}

printf(“nums: %d\nchars: %d\n”,nums,chars);

return 0;
}

#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 1000010;

int primes[N], cnt;
bool st[N];

void init(int n)
{
memset(st, 0, sizeof st);
cnt = 0;
for (int i = 2; i <= n; i ++ )
{
if (!st[i]) primes[cnt ++ ] = i;
for (int j = 0; primes[j] * i <= n; j ++ )
{
st[i * primes[j]] = true;
if (i % primes[j] == 0) break;
}
}
}

int main()
{
int l, r;
while (cin >> l >> r)
{
init(50000);

memset(st, 0, sizeof st);
for (int i = 0; i < cnt; i ++ )
{
LL p = primes[i];
for (LL j = max(p * 2, (l + p - 1) / p * p); j <= r; j += p)
st[j - l] = true;
}

cnt = 0;
for (int i = 0; i <= r - l; i ++ )
if (!st[i] && i + l >= 2)
primes[cnt ++ ] = i + l;

if (cnt < 2) puts("There are no adjacent primes.");
else
{
int minp = 0, maxp = 0;
for (int i = 0; i + 1 < cnt; i ++ )
{
int d = primes[i + 1] - primes[i];
if (d < primes[minp + 1] - primes[minp]) minp = i;
if (d > primes[maxp + 1] - primes[maxp]) maxp = i;
}

printf("%d,%d are closest, %d,%d are most distant.\n",
primes[minp], primes[minp + 1],
primes[maxp], primes[maxp + 1]);
}
}

return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

const int N= 1000010;

int primes[N], cnt;
bool st[N];

void get_primes(int n)
{
for (int i = 2; i <= n; i ++ )
{
if (st[i]) continue;
primes[cnt ++ ] = i;
for (int j = i + i; j <= n; j += i)
st[j] = true;
}
}

int main()
{
int n;
cin >> n;

get_primes(n);

cout << cnt << endl;

return 0;
}



#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 1010;

int primes[N], cnt;
int sum[N];
bool st[N];

void get_primes(int n)
{
for (int i = 2; i <= n; i ++ )
{
if (!st[i]) primes[cnt ++ ] = i;
for (int j = 0; primes[j] * i <= n; j ++ )
{
st[primes[j] * i] = true;
if (i % primes[j] == 0) break;
}
}
}

int main()
{
int T;
scanf("%d", &T);

get_primes(N - 1);

for (int i = 1; i < cnt; i ++ )
{
int s = primes[i] + primes[i - 1] + 1;
if (s < N && !st[s])
sum[s] = 1;
}

for (int i = 1; i < N; i ++ ) sum[i] += sum[i - 1];

while (T -- )
{
int n, k;
scanf("%d%d", &n, &k);
if (sum[n] >= k) puts("YES");
else puts("NO");
}

return 0;
}



#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 5010;

int n, m;
int s[N][N];

int main()
{
int cnt, R;
cin >> cnt >> R;
R = min(5001, R);

n = m = R;
while (cnt -- )
{
int x, y, w;
cin >> x >> y >> w;
x ++, y ++ ;
n = max(n, x), m = max(m, y);
s[x][y] += w;
}

// 预处理前缀和
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= m; j ++ )
s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];

int res = 0;

// 枚举所有边长是R的矩形，枚举(i, j)为右下角
for (int i = R; i <= n; i ++ )
for (int j = R; j <= m; j ++ )
res = max(res, s[i][j] - s[i - R][j] - s[i][j - R] + s[i - R][j - R]);

cout << res << endl;

return 0;
}



2023.02.12.11.53

import java.util.Scanner;

public class Main{
private static int fact(int n){
int res = 1;
for (int i = 1;i<=n; i++)
res*=i;
return res;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(fact(n));
}
}


2.12

import java.util.Scanner;

public class Main{
private static int fact(int n){
int res = 1;
for (int i = 1;i<=n; i++)
res*=i;
return res;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(fact(n));
}
}