多项式输出

模拟

 /*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] 普及组的更多相关文章

  1. NOIP2009普及组细胞分裂(数论)——yhx

    题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家.现在,他正在为一个细胞实 验做准备工作:培养细胞样本. Hanks 博士手里现在有 N 种细胞,编号从 1~N,一个 ...

  2. [NOIp2009普及组]细胞分裂

    思路: 首先将$30000$以内的所有质数求出,再对$m1$质因数分解. 对于每个$s$,计算它和$m1$的每个公共质因数的倍数关系,取$max$则为该细胞满足条件所花费的最少时间. 再对于每个细胞的 ...

  3. 洛谷 1067 NOIP2009 普及组 多项式输出

    [题解] 一道简单的模拟题.需要判一些特殊情况:第一项的正号不用输出,x的一次项不用输出指数,系数为0的项不用输出等等,稍微细心一下就好. #include<cstdio> #includ ...

  4. noip2017普及组

    过了这么久才来写博客,也是我这么一段时间都很低迷吧.... 老实来说,今年应该是要打提高组的...可还是打了普及组... 其实最猥琐的还是我连普及都写挂了,作为一个学了两年的人,图论,进阶dp都写过的 ...

  5. NOIP2002-2017普及组题解

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

  6. noip2017爆炸记——题解&总结&反省(普及组+提高组)

    相关链接: noip2018总结 noip2017是我见过的有史以来最坑爹的一场考试了. 今年北京市考点有一个是我们学校,我还恰好被分到了自己学校(还是自己天天上课的那个教室),于是我同时报了普及提高 ...

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

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

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

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

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

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

随机推荐

  1. KVM虚拟机CPU说明

    废话不多说了,下面对kvm虚拟机的CPU说明做一梳理:NUMA技术介绍NUMA是一种解决多CPU共同工作的技术方案,我们先回顾下多CPU共同工作的技术架构历史.多CPU共同工作主要有三种架构,分别是S ...

  2. UINavagationController

    如何防止navigation多次push一个页面?有时候网慢,点了一下没反应,用户可能就多点几下,这时候会打开好几个一样的页面: 写了一个navigation基类,重写了push方法:传进来要push ...

  3. JavaScript实现级联下拉框

    <!DOCTYPE html> <html> <head> <meta name="author" content="Yeeku ...

  4. 点击劫持(CLICKJACKING)与X-FRAME-OPTIONS HEADER

    转载: http://www.tuicool.com/articles/mqUBfa 目录 前言 1.1 点击劫持(clickjacking attacks) 1.2  Frame Bursters. ...

  5. linux下的zip命令

    1.把/home目录下面的mydata目录压缩为mydata.zipzip -r mydata.zip mydata #压缩mydata目录2.把/home目录下面的mydata.zip解压到myda ...

  6. C++ Set & MultiSet

    转自http://www.cppblog.com/wanghaiguang/archive/2012/06/05/177627.html STL Set介绍集合(Set)是一种包含已排序对象的关联容器 ...

  7. yield(C# 参考)

    yield(C# 参考) 在语句中使用 yield 关键字,表示在该关键字所在的方法.运算符或 get 访问器是迭代器.   通过使用 yield 定义迭代器,可在实现自定义集合类型的 IEnumer ...

  8. 我们为什么需要DTO?

    看了几套源码,其中都有用到DTO,这篇文章主要来谈论一下DTO使用的场合及其带来的好处. 在传统的编程中,我们一般都是前台请求数据,发送到Webservice,然后WebService向数据库发出请求 ...

  9. 执行mount命令时找不到介质或者mount:no medium found的解决办法

    使用vmware时,在虚拟机设置里,设置CD/DVD为系统镜像,挂载时,有时会有找不到介质或者no medium found之类的提示. 根本原因是iso镜像并没有加载到虚拟机系统内. 解决办法: 首 ...

  10. Linux常用指令---find | locate(查找)

    1.locate locate指令和find找寻档案的功能类似,但locate是透过update程序将硬盘中的所有档案和目录资料先建立一个索引数据库,在 执行loacte时直接找该索引,查询速度会较快 ...