The 13th Chinese Northeast Collegiate Programming Contest

本文介绍了第13届中国东北大学生编程竞赛中的部分题目,包括平衡饮食问题的贪心策略、直线交点判断、最小子树生成、数据结构大师挑战、赛前小游戏解析、雷达扫描优化以及摩天大楼问题的解决方法。涉及到贪心算法、几何问题、图论以及动态规划等编程技巧。
摘要由CSDN通过智能技术生成

链接

B. Balanced Diet

贪心,假设最大天数为k,那么所有物品最大得k项都拿(再满足题意的情况下)

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int maxn = 2e6 + 6;
const LL inf = 0x3f3f3f3f;
const int mod = 1e9+9;
LL qp(LL x,LL y){
   LL ans=1;x%=mod;while(y){
   if(y&1) ans=ans*x%mod;x=x*x%mod;y>>=1;}return ans;}
//LL __gcd(LL x,LL y){return y==0?x:__gcd(y,x%y);}
//head
int n,_,p[maxn],m,mx;
LL s[maxn];
VI G[maxn];
int main(){
   
    scanf("%d",&_);
    while(_--){
   
         scanf("%d%d",&n,&m);
         for(int i=1;i<=m;i++){
   
             scanf("%d",&p[i]);
             G[i].clear();
         }
         for(int i=1,x,y;i<=n;i++){
   
             scanf("%d%d",&x,&y);
             G[y].pb(x);
         }
         for(int i=1;i<=m;i++){
   
             sort(G[i].begin(),G[i].end());
             reverse(G[i].begin(),G[i].end());
         }
         for(int i=1;i<=m;i++){
   
             LL sum=0;
             for(int j=0;j<G[i].size();j++){
   
                s[max(j+1,p[i])]+=G[i][j];
                //printf("%llds",sum);
             }
         }
         LL zi=0,mu=1;
         for(int i=1;i<=n;i++) s[i]+=s[i-1];
         for(LL i=1;i<=n;i++){
   
             if(zi*i<s[i]*mu) zi=s[i],mu=i;
             //printf("%lld",s[i]);
             s[i]=0;
         }
         LL gcd=__gcd(zi,mu);
         printf("%lld/%lld\n",zi/gcd,mu/gcd);
    }
}

C. Line-line Intersection

两条直线有交点即斜率不同,用mp模拟就好(脑子抽抽,错了十几次😟)

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int maxn = 1e5 + 6;
const LL inf = 0x3f3f3f3f;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值