[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 ...
随机推荐
- Statistics gathering and SQL Tuning Advisor
1. https://www.pythian.com/blog/statistics-gathering-and-sql-tuning-advisor/ Our monitoring software ...
- AngularJS入门 & 分页 & CRUD示例
一.AngularJS 简介 AngularJS 诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前端JS框架,已经被用于Google的多款产品当中. ...
- sql 关键字的用法
coalesce( T.GoodsCode,'0') 若 T.GoodsCode 为NULL 这 用0替换 round(S.SaleEarning,2) 保留两位小数 SUBSTRING(zb.acc ...
- SharedPrefences的用处
存储数据 SharedPreferences.Editor edit = getSharedPreferences("data", MODE_PRIVATE).edit(); ed ...
- Android习惯--Activity启动方法
public void Text extends Activity{ public void static actionStart(Context context, int i, String str ...
- 如需在APP中使用腾讯QQ登陆,需提前申请获取腾讯QQ的APPKEY和APPSecret。
如需在APP中使用腾讯QQ登陆,需提前申请获取腾讯QQ的APPKEY和APPSecret. 申请流程如下: 步骤1:登陆腾讯开放平台.链接地址: http://open.qq.com/ . 步骤2:填 ...
- 中国版 Office 365 (X-Tenant / Tango) 功能验证报告 - 2 基本步骤
说明: 1. 前期准备 - 在Azure上模拟出生产环境: 包括父域域控.子域域控.父域的Exchange Server.子域的Exchange Server.对Exchange Server, 需要 ...
- 说说C#中list与IList中的区别(转载)
首先IList 泛型接口是 ICollection 泛型接口的子代,并且是所有泛型列表的基接口. 但是它仅仅是所有泛型类型的接口,并没有太多方法可以方便实用,如果仅仅是作为集合数据的承载体,确实,IL ...
- ArrayList集合的特点和几种遍历方法
public class temp { public static void main(String[] args)throws Exception { ArrayList 在定义时长度为空 ,在新增 ...
- 【MSSQL】MDF、NDF、LDF文件的含义
[MSSQL]MDF.NDF.LDF文件的含义 2012-09-03 15:32:56| 分类: SQL数据库|举报|字号 订阅 MDF是 primary data file 的缩写:NDF ...