2.16普及组打卡题目

是泡泡 每日一题总教官
云计算领域优质创作者
2023-02-16 15:06:34

奶牛

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
#define x first
#define y second
#define ms(a,s) memset(a, s, sizeof a);
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
const int mod = 1e6+7;
const int inf = 0x3f3f3f3f;
const int N = 5e4 + 10;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
struct node {
	int w, s;
}a[N];
bool cmp(node a, node b) {
	return a.w + a.s < b.w + b.s;
}
void solve() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++ ) {
		cin >> a[i].w >> a[i].s;
	}
	sort(a + 1, a + 1 + n, cmp);
	int ans = -1e6, k = 0;
	for(int i = 1; i <= n; i ++ ) {
		ans = max(ans, k - a[i].s);
		k += a[i].w;
	}
	cout << ans;
}
int main()
{
	int t = 1;

//	cin >> t;

	while(t --) {
		solve();
	}

	return 0;
}

nasa

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
#define x first
#define y second
#define ms(a,s) memset(a, s, sizeof a);
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
const int mod = 1e6+7;
const int inf = 0x3f3f3f3f;
const int N = 1010;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int a[N], w[N], v[N], f[N][N];
void solve() {
	int h, t, n;
	cin >> h >> t >> n;
	for(int i = 1; i <= n; i ++ ) {
		cin >> w[i] >> v[i] >> a[i];
	}
	for(int i = 1; i <= n; i ++ ) {
		for(int j = h; j >= w[i]; j -- ) {
			for(int k = t; k >= v[i]; k -- ) {
				f[j][k] = max(f[j][k], f[j - w[i]][k - v[i]] + a[i]);
			}
		}
	}
	cout << f[h][t];
}
int main()
{
	int t = 1;

//	cin >> t;

	while(t --) {
		solve();
	}

	return 0;
}

 

...全文
1305 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
SoftwareTeacher 2023-03-04
精选
  • 打赏
  • 举报
回复
5.00元

坚持练习!

执梗 2023-03-04
  • 打赏
  • 举报
回复

回文日期

import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
   public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int data = sc.nextInt();
    huiwenriqi(data);
    ABhuiwenriqi(data);
    sc.close();
}
public static void huiwenriqi(int n) {
    for (int i = n+1; i <= 89991231; i++) {
        String str = i+"";
        char[] ch = str.toCharArray();
        char a = ch[0], b = ch[1], c = ch[2], d = ch[3],e = ch[4],f = ch[5],g = ch[6],h = ch[7];
        if(a==h&&b==g&&c==f&&d==e) {
            System.out.println(ch);
            break;
        }
}
}
public static void ABhuiwenriqi(int n) {
    for (int i = n+1; i <= 89991231; i++) {
        String str = i+"";
        char[] ch = str.toCharArray();
        char a = ch[0], b = ch[1], c = ch[2], d = ch[3],e = ch[4],f = ch[5],g = ch[6],h = ch[7];
        if(a==c&&c==f&&f==h&&b==d&&d==e&&e==g) {
            System.out.println(ch);
            break;
        }
}
    
}
}
Devoted~ 2023-03-03
  • 打赏
  • 举报
回复

import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
      int n = 2;
      int count = 0;
      while(true){
        if(isPrime(n)){
          count++;
        }

        if(count==2019){
          break;
      }
      n++;
      }
      System.out.println(n);
        scan.close();
    }
    public static boolean isPrime(int m){
      for(int i = 2;i<=Math.sqrt(m);i++){
        if(m%i==0){
          return false;
        }
      }
      return true;
    }
}

img

Devoted~ 2023-03-03
  • 打赏
  • 举报
回复
import java.util.Scanner;
public class Main {
  static int N = 20190330;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int []a =  new int[N];
        a[0] = 1;
        a[1] = 1;
        a[2] = 1;
        for(int i=3;i<=20190324;i++){
        a[i] = (a[i-3]+a[i-2]+a[i-1])%10000;
        }
        System.out.println(a[20190323]);
        scan.close();
    }
}

img

浅夜呀 2023-03-03
  • 打赏
  • 举报
回复

public class Main{
    public static void main(String[] args) {
        int a = 1, b = 1, c = 1, d = 0;
        for(int i = 4; i <= 20190324; i++){
            d = (a + b + c) % 10000;//每次求和都取10000的模,就不会超范围了
            a = b;
            b = c;
            c = d;
        }
        System.out.println(d);
    }
}

img

浅夜呀 2023-03-03
  • 打赏
  • 举报
回复

public class Main {
    public static void main(String[] args) {
        int x = 2;
        int cnt = 1;
        while (cnt < 2019) {
            x++;
            if (isPrime(x)) cnt++;
        }
        System.out.println(x);
    }

    static boolean isPrime(int x) {
        for (int i = 2; i <= x / i; i++) {
            if (x % i == 0) return false;
        }
        return true;
    }
}

img

51,714

社区成员

发帖
与我相关
我的任务
社区描述
和众多高校算法内卷分子,一起学习和交流算法那。浓郁的算法交流氛围,拒绝躺平,有效内卷。加入我们,私信我拉你入核心内卷群。
算法数据结构leetcode 个人社区
社区管理员
  • 执 梗
  • Dream-Y.ocean
  • ღCauchyོꦿ࿐
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

 刷题!

试试用AI创作助手写篇文章吧