[NOIP2007] 普及组
模拟
开个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 ;
}
守望者的逃离
普通的汉诺塔方案数是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] 普及组的更多相关文章
- C++算法代码——纪念品分组[NOIP2007 普及组]
题目来自:http://218.5.5.242:9018/JudgeOnline/problem.php?id=1099 https://www.luogu.com.cn/problem/P1094 ...
- [洛谷P1095]NOIP2007 普及组T3 守望者的逃离
问题描述 恶魔猎手尤迪安野心勃勃,他背叛了暗夜精灵,率领深藏在海底的娜迦族企图叛变.守望者在与尤迪安的交锋中遭遇了围杀,被困在一个荒芜的大岛上.为了杀死守望者,尤迪安开始对这个荒岛施咒,这座岛很快就会 ...
- NOIP2002-2017普及组题解
虽然普及组一般都是暴力省一,但是有一些题目还是挺难的qwq个人觉得能进TG的题目会在前面打上'*' NOIP2002(clear) #include<bits/stdc++.h> usin ...
- NOIP2012 普及组 T3 摆花——S.B.S.
题目描述 小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆.通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号.为了在门口展出更多种花,规定第i种花不能超过ai盆,摆花时 ...
- NOIP2016普及组复赛解题报告
提高组萌新,DAY1DAY2加起来骗分不到300,写写普及组的题目聊以自慰. (附:洛谷题目链接 T1:https://www.luogu.org/problem/show?pid=1909 T2:h ...
- 05:统计单词数【NOIP2011复赛普及组第二题】
05:统计单词数 总时间限制: 1000ms 内存限制: 65536kB 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...
- [题解]noip2016普及组题解和心得
[前言] 感觉稍微有些滑稽吧,毕竟每次练的题都是提高组难度的,结果最后的主要任务是普及组抱一个一等奖回来.至于我的分数嘛..还是在你看完题解后写在[后记]里面.废话不多说,开始题解. 第一题可以说的内 ...
- NOIP2016普及组
普及组.代码有空发. 第一题就是买铅笔.暴力模拟绝对可取. 第二题就是回文日期.从t1的年份到t2的年份枚举每一年.头尾要特判. 第三题就是海港.骗了40分. 第四题就是魔法阵.不太好优化. 完.
- [NOIP2013] 普及组
计数问题 纯模拟 #include<cstdio> #include<iostream> using namespace std; int main(){ int n,x; c ...
随机推荐
- 467 Unique Substrings in Wraparound String 封装字符串中的独特子字符串
详见:https://leetcode.com/problems/unique-substrings-in-wraparound-string/description/ C++: class Solu ...
- sed与正则表达式
行的开头(^) ^匹配每一行的开头 [root@sishen ~]# sed -n '/^103/ p ' employee.txt 103,Raj Reddy,Sysadmin 只有^出现在正则表达 ...
- Repeater 的使用
<HeaderTemplate></HeaderTemplate> 头模板——在加载开始执行一遍 <FooterTemplate></FooterTempl ...
- Laravel5中防止XSS跨站攻击的方法
本文实例讲述了Laravel5中防止XSS跨站攻击的方法.分享给大家供大家参考,具体如下: Laravel 5本身没有这个能力来防止xss跨站攻击了,但是这它可以使用Purifier 扩展包集成 HT ...
- java基础(六):RabbitMQ 入门
建议先了解为什么项目要使用 MQ 消息队列,MQ 消息队列有什么优点,如果在业务逻辑上没有此种需求,建议不要使用中间件.中间件对系统的性能做优化的同时,同时增加了系统的复杂性也维护难易度:其次,需要了 ...
- 怪物猎人OL简单测评与碎碎念
请移步我的个人网站查看: www.wuduojia.cn
- nodejs idea 创建项目 (一)
1.在工作空间创建module file->new module next next 项目的目录结构: bin:跟业务无关的公共部分 node_modules :默认的模块 public:公共模 ...
- c++ 模板template
1.函数模板的声明 声明形式 template<typename 数据类型参数标识符> <返回类型><函数名>(参数表) { 函数体 } 注: templa ...
- thinkphp5中vendor的使用?
1.创建处理数组的类ArrayList.php <?php /** * ArrayList实现类 * @author liu21st <liu21st@gmail.com> */ c ...
- Oracle中如何插入特殊字符: &amp; 和 &#39; (多种解决方案)
Oracle中如何插入特殊字符:& 和 ' (多种解决方案)今天在导入一批数据到Oracle时,碰到了一个问题:Toad提示要给一个自定义变量AMP赋值,一开始我很纳闷,数据是一系列的Inse ...