程序设计新题

 头文件&宏定义

#include <iostream>
#include <string.h>
#include <math.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <vector>
#include <set>

#define ll long long//是ll在前面
#define IOS ios::sync_with_stdio(0), cin.tie(0);

typedef pair<int,string> PICK;

using namespace std;

map<int,int> mp;
int a[120000]={0};//至少100000个数据
//小明手上的牌2
//在之前那道题的基础上改成了后面的牌每次取最小的 其实对后面的数排个序就可以了
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
 
using namespace std;
typedef long long i64;
 
priority_queue<int,vector<int>,greater<int>> Q;
 
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int a[m],b[n-m];
    for(int i=0;i<m;i++)
    {
        scanf("%d",&a[i]);
        Q.push(a[i]);
    }
    for(int j=0;j<n-m;j++)
        scanf("%d",&b[j]);
    sort(b,b+n-m);
    for(int j=0;j<n-m;j++)
    {
        Q.pop();
        Q.push(b[j]);
    }
    cout<<Q.top()<<endl;
    return 0;
}
//它不是丑数
#include <iostream>
#include <algorithm>
#define homo 114514
using namespace std;
typedef long long i64;
int ugly[homo]={0};
 
int main()
{
    //先预处理ugly数组
    int l2=1,l3=1,l5=1;
    ugly[1]=1;
    for(int i=2;i<=homo;i++)
    {
        ugly[i]=min(ugly[l2]*2,min(ugly[l3]*3,ugly[l5]*5));
        if(ugly[i]==ugly[l2]*2) l2++;
        if(ugly[i]==ugly[l3]*3) l3++;
        if(ugly[i]==ugly[l5]*5) l5++;
        //这里不要手贱加上else 会少很多情况的
    }
    int T=1;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        int count=0;
        int i=0;//记录第几个丑数
        while(count<n)
        {
            count=count+ugly[i+1]-ugly[i]-1;
            i++;
        }
        i--;
        count=count-(ugly[i+1]-ugly[i]-1);
        printf("%d\n",ugly[i]+n-count);
    }
    return 0;
}

//游戏高手
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<vector<int> > grid(n, vector<int>(m));
    vector<vector<int> > dp(n, vector<int>(m, 0));

    // 输入网格
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> grid[i][j];
        }
    }

    // 初始化起点
    dp[0][0] = grid[0][0];

    // 初始化第一行
    for (int j = 1; j < m; ++j) {
        dp[0][j] = dp[0][j-1] + grid[0][j];
    }

    // 初始化第一列
    for (int i = 1; i < n; ++i) {
        dp[i][0] = dp[i-1][0] + grid[i][0];
    }

    // 填充DP表
    for (int i = 1; i < n; ++i) {
        for (int j = 1; j < m; ++j) {
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + grid[i][j];
        }
    }

    // 输出结果
    cout << dp[n-1][m-1] << endl;

    return 0;
}
//落花清理
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

    priority_queue<int, vector<int>, greater<int> > pq; // 最小堆
    //在声明优先队列时,将 >> 改为 > >。
    //注意这里的修改,这可以防止编译器将连续的两个 > 误认为是右移操作符。
    for (int i = 0; i < n; ++i) {
        int weight;
        cin >> weight;
        pq.push(weight);
    }

    int total_cost = 0;

    while (pq.size() > 1) {
        int first = pq.top();
        pq.pop();
        int second = pq.top();
        pq.pop();

        int combined_weight = first + second;
        total_cost += combined_weight;

        pq.push(combined_weight);
    }

    cout << total_cost << endl;

    return 0;
}
//抽到的题目的新题目  小明的手牌

//感觉考的是基础内容  很容易想到  但是要懂得基本函数的使用
//这道题用到了向量、set维护手牌(自动维护从小到大的顺序,并且允许重复数字的出现)、排序sort
//set和multiset的区别(不允许重复数字、允许重复数字)

//ms.erase(1);
//直接删除 multiset 中所有值为 1 的元素。如果 1 存在多个实例,它们都会被删除。返回值是被删除的元素的数量。
//ms.erase(ms.find(1));
//ms.find(1) 会返回一个指向值为 1 的元素的迭代器。只删除第一个找到的 1,适用于你只想删除一个特定的元素。

/*for (int x : s)
{
    cout << x << " ";
}
s 可能是 vector、set、list 或其他支持范围基 for 循环的容器类型。
int x:表示每次循环时,s 中的当前元素的值将被赋给变量 x
*/



#include <iostream>
#include <vector>
#include <set>
#include <algorithm> // 用于排序

using namespace std;
//错了两个地方
int main()
{
    int n,m;
    cin>>n>>m;

    vector<int>s(n);
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
    }
    set<int>shou;
    for(int i=0;i<m;i++)
    {
        shou.insert(s[i]);
    }
    sort(s.begin()+m,s.end());
    for(int i=m;i<n;i++)//循环i的值的设置
    {
        shou.erase(shou.begin());
        shou.insert(s[i]);//这里没有用到i的值,失去了循环的意义
    }
    cout<<*shou.begin()<<endl;//因为shou是用的set定义,所以不能像s一样可以用数组输出
                              //shou.begin()返回的是迭代器,需要使用* 来获取迭代器指向的实际元素。
    return 0;
}

    // 输出手牌中最小的编号
    cout << *hand.begin() << endl;

    return 0;
}
//偷懒的士兵3

bool Check(int n, int m) {
	if (n < 3) {
		return false;
	}
	if (n == 3) {
		return true;
	}
	if (m % 2) { // 如果站位是奇数
		return Check((n + 1) / 2, (m + 1) / 2); // 去除站位是偶数的士兵
	}
	else {
		return Check(n / 2, m / 2); // 去除站位是奇数的士兵
	}
}

int main() {
	IOS;
	int n, m;
	while (cin >> n >> m && n && m) {
		cout << (Check(n, m) ? 'Y' : 'N') << endl;
	}
	return 0;
}
//校赛排名2
#include <iostream>
#include <algorithm>
#include <cstring>
 
using namespace std;
typedef long long i64;
struct team
{
    char name[20];
    bool accepted[200]={false};
    int time[200]={0};
    int all_ac=0;
    int all_time=0;
} all[100000];
bool cmp(team a,team b)
{
    if(a.all_ac==b.all_ac)
        return a.all_time<b.all_time;
    return a.all_ac>b.all_ac;
}
 
int main()
{
    int n=0;//记录总队伍数
    int now_time=0,if_ac=0;
    char team_name[20],question;
    while(scanf("%d %s %c %d",&now_time,team_name,&question,&if_ac)!=EOF)
    {
        int flag=0;//找这个队之前有没有提交过
        int i;
        for(i=0;i<n;i++)
        {
            if(!strcmp(team_name,all[i].name))
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            strcpy(all[n].name,team_name);
            i=n;
            n++;
        }
        if(if_ac==0)
        {
            all[i].accepted[question]=true;
            all[i].time[question]+=now_time;
        }
        else
        {
            if(!all[i].accepted[question])
            {
                all[i].time[question]+=20;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j='A';j<='O';j++)
        {
            if(all[i].accepted[j])
            {
                all[i].all_ac++;
                all[i].all_time+=all[i].time[j];
            }
        }
    }
    sort(all,all+n,cmp);
    for(int i=0;i<n;i++)
    {
        if(all[i].all_ac==0)
            break;
        printf("%s %d %d\n",all[i].name,all[i].all_ac,all[i].all_time);
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zero_019

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值