奖学金

模拟

开个struct排序即可 c++吼啊

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct stu{
int ch,ma,en;
int tot;
int id;
}s[];
int cmp(stu a,stu b){
if(a.tot!=b.tot)return a.tot>b.tot;
if(a.ch!=b.ch)return a.ch>b.ch;
return a.id<b.id;
}
int n;
int main(){
n=read();
int i,j;
for(i=;i<=n;i++){
s[i].ch=read();s[i].ma=read();s[i].en=read();
s[i].tot=s[i].ch+s[i].en+s[i].ma;
s[i].id=i;
}
sort(s+,s+n+,cmp);
for(i=;i<=;i++){
printf("%d %d\n",s[i].id,s[i].tot);
}
return ;
}

奖学金

纪念品分组

贪心

价值从小到大排序。每次把最大的和最小的组合在一起(如果不能组合,那么最大的单独成为一组)

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int w,n;
int p[mxn];
int main(){
w=read();n=read();
int i,j;
for(i=;i<=n;i++) p[i]=read();
sort(p+,p+n+);
int hd=,tl=n;
int cnt=;
while(hd<=tl){
if(p[hd]+p[tl]<=w)cnt++,hd++,tl--;
else tl--,cnt++;
}
printf("%d\n",cnt);
return ;
}

纪念品分组

守望者的逃离

DP

能闪则闪。不能闪的时候,同时处理原地回蓝和一直跑两个状态,如果回蓝后闪烁比跑的距离更远,就更新距离。

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int m,s,t;
int main(){
scanf("%d%d%d",&m,&s,&t);
int i,j;
int now=;
int tst=;
for(i=;i<=t;i++){
if(m>=){
tst+=;
m-=;
}
else m+=;
if(tst>now+)now=tst;
else now+=;
if(now>=s)break;
}
if(i>t)printf("No\n%d\n",now);
else printf("Yes\n%d\n",i);
return ;
}

守望者的逃离

Hanoi双塔问题

普通的汉诺塔方案数是f(n)=2^n-1

这里因为两个盘等价,方案数直接乘2变成2^(n+1)-2

一个高精乘单精就可以解决,之后末尾直接-2 (因为2的次方数,个位只能是2 4 6 8的一种,所以不需要借位)

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int len=;
int a[mxn];
int main(){
int i,j,n;
scanf("%d",&n);
a[]=;
for(i=;i<=n;i++){
for(j=len;j;j--){
a[j]*=;
a[j+]+=a[j]/;
a[j]%=;
}
if(a[len+]) ++len;
}
a[]-=;
for(i=len;i;i--)printf("%d",a[i]);
printf("\n");
return ;
}

hanoi双塔

[NOIP2007] 普及组的更多相关文章

  1. C++算法代码——纪念品分组[NOIP2007 普及组]

    题目来自:http://218.5.5.242:9018/JudgeOnline/problem.php?id=1099 https://www.luogu.com.cn/problem/P1094 ...

  2. [洛谷P1095]NOIP2007 普及组T3 守望者的逃离

    问题描述 恶魔猎手尤迪安野心勃勃,他背叛了暗夜精灵,率领深藏在海底的娜迦族企图叛变.守望者在与尤迪安的交锋中遭遇了围杀,被困在一个荒芜的大岛上.为了杀死守望者,尤迪安开始对这个荒岛施咒,这座岛很快就会 ...

  3. NOIP2002-2017普及组题解

    虽然普及组一般都是暴力省一,但是有一些题目还是挺难的qwq个人觉得能进TG的题目会在前面打上'*' NOIP2002(clear) #include<bits/stdc++.h> usin ...

  4. NOIP2012 普及组 T3 摆花——S.B.S.

    题目描述 小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆.通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号.为了在门口展出更多种花,规定第i种花不能超过ai盆,摆花时 ...

  5. NOIP2016普及组复赛解题报告

    提高组萌新,DAY1DAY2加起来骗分不到300,写写普及组的题目聊以自慰. (附:洛谷题目链接 T1:https://www.luogu.org/problem/show?pid=1909 T2:h ...

  6. 05:统计单词数【NOIP2011复赛普及组第二题】

    05:统计单词数 总时间限制:  1000ms 内存限制:  65536kB 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...

  7. [题解]noip2016普及组题解和心得

    [前言] 感觉稍微有些滑稽吧,毕竟每次练的题都是提高组难度的,结果最后的主要任务是普及组抱一个一等奖回来.至于我的分数嘛..还是在你看完题解后写在[后记]里面.废话不多说,开始题解. 第一题可以说的内 ...

  8. NOIP2016普及组

    普及组.代码有空发. 第一题就是买铅笔.暴力模拟绝对可取. 第二题就是回文日期.从t1的年份到t2的年份枚举每一年.头尾要特判. 第三题就是海港.骗了40分. 第四题就是魔法阵.不太好优化. 完.

  9. [NOIP2013] 普及组

    计数问题 纯模拟 #include<cstdio> #include<iostream> using namespace std; int main(){ int n,x; c ...

随机推荐

  1. python_数据类型基本操作(2)

    概览: 第1章 基础数据类型宏观的初识第2章 int 第3章 bool 第4章 str 4.1 python体现形式 4.2 引号用法 4.3 字符串运算 4.3.1 字符串相加 4.3.2 字符串相 ...

  2. 04全志R58平台编译内核需要选择的配置

    04全志R58平台编译内核需要选择的配置 2018/11/6 14:19 版本:V1.0 开发板:SC5806 1.系统编译:(略) 每次系统编译/内核的时候都需要选3次N: * * Xtables ...

  3. 读取Java文件到byte数组的三种方式

    package zs; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io ...

  4. Locations for Public Frameworks

    Locations for Public Frameworks Third-party frameworks can go in a number of different file-system l ...

  5. laravel如何自定义控制器目录

    默认控制器在App\Http\Controllers目录下,如何自定义目录呢? 首先我们看一下laravel的请求周期 我们看一下服务提供者RouteServicePrivder文件中的一个函数 /* ...

  6. Webstorm 的 Tab 键调整缩进值

    两步即可,注意版本

  7. jdk5.0新增两个线程创建方法

    1.实现callable接口 import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; ...

  8. 【软件构造】(转)Java中的comparable和comparator

    为了方便阅读和复习,转载至此,原地址:温布利往事的博客 阅读目录 一.Comparable简介 二.Comparator简介 三.Comparable和Comparator区别比较 回到顶部 一.Co ...

  9. thinkphp5中vendor的使用?

    1.创建处理数组的类ArrayList.php <?php /** * ArrayList实现类 * @author liu21st <liu21st@gmail.com> */ c ...

  10. torch.nn.Linear()函数的理解

    import torch x = torch.randn(128, 20) # 输入的维度是(128,20)m = torch.nn.Linear(20, 30) # 20,30是指维度output ...