[NOIP2009] 普及组
模拟
/*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 n,a[mxn];
void solve(int x,int c){
if(!c)return;
if(!x){
if(c>){
if(x==n)printf("%d",c);
else printf("+%d",c);
}
else printf("%d",c);
return;
}
if(x==){
if(c==){
if(x==n)printf("x");
else printf("+x");
}
else if(c==-)printf("-x");
else if(c>)printf("+%dx",c);
else printf("%dx",c);
return;
}
if(x==n){
if(c==)printf("x^%d",x);
else if(c==-)printf("-x^%d",x);
else printf("%dx^%d",c,x);
return;
}
if(c>){
if(c==)printf("+x^%d",x);
else printf("+%dx^%d",c,x);
return;
}
if(c<){
if(c==-)printf("-x^%d",x);
else printf("%dx^%d",c,x);//
}
return;
}
int main(){
n=read();
for(int i=n;i>=;i--)a[i]=read();
for(int i=n;i>=;i--){
solve(i,a[i]);
}
printf("\n");
return ;
}
多项式输出
然而翻记录发现之前写过超短的代码……
天呐仿佛退化了
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,k;
cin>>n;
for(int i=n;i>=;i--)
{
cin>>k;
if(k==)
continue;//系数为0不输出
if(k>)
if(i!=n)
cout<<"+";//直接判断符号
if(k<)
cout<<"-";
k=abs(k);//输出绝对值
if(k!=||i==)
cout<<k;
if(i!=)
if(i!=)
cout<<"x^"<<i;
else
cout<<"x";
}
}
多项式输出
按题目要求自定义compare函数,一发sort
/*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 info{
int id,sc;
}a[mxn];
int cmp(info a,info b){
if(a.sc!=b.sc)return a.sc>b.sc;
return a.id<b.id;
}
int n,m;
int main(){
n=read();m=read();
m=floor((double)m*1.5);
for(int i=;i<=n;i++){
a[i].id=read();
a[i].sc=read();
}
sort(a+,a+n+,cmp);
while(a[m+].sc==a[m].sc && m<n)m++;
printf("%d %d\n",a[m].sc,m);
for(int i=;i<=m;i++){
printf("%d %d\n",a[i].id,a[i].sc);
}
return ;
}
分数线划定
对目标值分解质因数。
再对每种可选细胞分解质因数,看需要分裂多少次可以使该种细胞的“每个质因数的次数”都比“目标值对应质因数的次数”大。
如果该细胞的质因数中没有目标值的质因数,则无解。
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
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 pri[mxn],pct=;
int cnt[mxn];
int n,m1,m2; void dvi(int m){
for(int i=;i<=m;i++){
if(m%i)continue;
pri[++pct]=i;
while(m%i==){
cnt[pct]++;
m/=i;
}
}
// for(int i=1;i<=pct;i++)printf("%d %d\n",pri[i],cnt[i]);
for(int i=;i<=pct;i++)cnt[i]*=m2;
return;
}
int ans;
int main(){
n=read();m1=read();m2=read();
dvi(m1);
int i,j;
ans=1e9;
int x;
while(n--){
x=read();
for(i=;i<=pct;i++){
// printf("test: x:%d pri:%d\n",x,pri[i]);
if(x%pri[i])break;
}
if(i<=pct)continue;
//
int tmp;
int res=;
for(int i=;i<=pct;i++){
tmp=;
while(x%pri[i]==){
tmp++;
x/=pri[i];
}
res=max(res,(int)ceil((double)cnt[i]/(double)tmp));
}
ans=min(ans,res);
}
if(ans==1e9)printf("-1\n");
else printf("%d\n",ans);
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 n,m,p;
int price[mxn];
int w[mxn][mxn];//时间为i,在j道路的金币数
int f[mxn];//时间为i,在j工厂的状态
void dp(){
int i,j,k;
int st;
for(i=;i<=m;++i){//时间
for(j=;j<=n;j++){//当前位置
st=j-;if(!st)st=n;
int tmp=w[st][i];
for(k=;k<=p;k++){
if(i-k<)break;
f[i]=max(f[i],f[i-k]+tmp-price[st]);
st--;if(!st)st=n;
tmp+=w[st][i-k];
}
}
}
printf("%d\n",f[m]);
return;
}
int main(){
n=read();m=read();p=read();
int i,j;
for(i=;i<=n;i++)//道路
for(j=;j<=m;j++){//时间
w[i][j]=read();
}
for(i=;i<=n;i++)price[i]=read();
dp();
return ;
}
动态规划
[NOIP2009] 普及组的更多相关文章
- NOIP2009普及组细胞分裂(数论)——yhx
题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家.现在,他正在为一个细胞实 验做准备工作:培养细胞样本. Hanks 博士手里现在有 N 种细胞,编号从 1~N,一个 ...
- [NOIp2009普及组]细胞分裂
思路: 首先将$30000$以内的所有质数求出,再对$m1$质因数分解. 对于每个$s$,计算它和$m1$的每个公共质因数的倍数关系,取$max$则为该细胞满足条件所花费的最少时间. 再对于每个细胞的 ...
- 洛谷 1067 NOIP2009 普及组 多项式输出
[题解] 一道简单的模拟题.需要判一些特殊情况:第一项的正号不用输出,x的一次项不用输出指数,系数为0的项不用输出等等,稍微细心一下就好. #include<cstdio> #includ ...
- noip2017普及组
过了这么久才来写博客,也是我这么一段时间都很低迷吧.... 老实来说,今年应该是要打提高组的...可还是打了普及组... 其实最猥琐的还是我连普及都写挂了,作为一个学了两年的人,图论,进阶dp都写过的 ...
- NOIP2002-2017普及组题解
虽然普及组一般都是暴力省一,但是有一些题目还是挺难的qwq个人觉得能进TG的题目会在前面打上'*' NOIP2002(clear) #include<bits/stdc++.h> usin ...
- noip2017爆炸记——题解&总结&反省(普及组+提高组)
相关链接: noip2018总结 noip2017是我见过的有史以来最坑爹的一场考试了. 今年北京市考点有一个是我们学校,我还恰好被分到了自己学校(还是自己天天上课的那个教室),于是我同时报了普及提高 ...
- 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 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...
随机推荐
- Flash Builder快捷键
代码助手:Ctrl+Space(简体中文操作系统是Alt+/)快速修正:Ctrl+1单词补全:Alt+/打开外部Java文档:Shift+F2 显示搜索对话框:Ctrl+H快速Outline:Ctrl ...
- Linux安装telnet
安装环境:CentOS 6.4 上篇已经讲述了memcached的安装,现在要测试Memcached功能的时候,需要使用到telnet服务.于是就有了本篇. 一.安装telnet 1.检测t ...
- BUG描述规范
BUG描述规范 一. 目的与适用范围 1.1 目的 报告软件测试错误的目的是为了保证修复错误的人员可以明确报告的错误,从而有利于分析错误产生的原因,定位错误,然后修正之.因此,报告软件测试错误的基本要 ...
- 无法解析此远程名称: 'www.***.com' 解决办法 请求因 HTTP 状态 417 失败
今天在做接口开发时,遇到了一个异常:无法解析此远程名称: 'www.***.com'.我的网站一直是运行正常的,从昨天开始出现异常,用户可以使用,但我的服务器怎么也无法实现对数据库的更新. 分析原因: ...
- 静态时序分析(static timing analysis) --- 时序路径
时序分析工具会找到且分析设计中的所有路径.每一个路径有一个起点(startpoint)和一个终点(endpoint).起点是设计中数据被时钟沿载入的那个时间点,而终点则是数据通过了组合逻辑被另一个时间 ...
- centos一键优化脚本
centos一键优化脚本:细节:http://oldboy.blog.51cto.com/2561410/1336488网络状态优化:http://oldboy.blog.51cto.com/2561 ...
- MTK 平台上查询当前使用的摄像头模组及所支持预览分辨率
1,MTK 平台如何查询当前使用的是哪颗摄像头及相关的模组信息? 在该目录下可以查到当前平台及相关项目的配置文件 ProjectConfig.mk \ALPS.JB.MP.V1_W_20120919\ ...
- 简谈Java的join()方法
join()是Thread类的一个方法.根据jdk文档的定义: public final void join()throws InterruptedException: Waits for this ...
- 获取技能的成功经验和关于C语言学习的调查 2015528
内容提要 你有什么技能比大多人(超过90%以上)更好?针对这个技能的获取你有什么成功的经验?与老师博客中的学习经验有什么共通之处? 有关C语言学习的调查 你是怎么学习C语言的?(作业,实验,教材,其他 ...
- ios —— UIViewAdditions 布局坐标类库
方便大家计算视图的高度,宽度,上下左右坐标,简化代码操作,更加直观 下载地址:http://download.csdn.net/detail/humingtao2013/7511657