多项式输出

模拟

 /*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. 【hibernate】<第一节>hibernate简单入门

    所需工具: ide:eclipse or myeclipse jdk:1.7 jar包:hibernate-distribution-3.6.0.Final 和对应mysql的驱动类(对应jar包如图 ...

  2. 啊D工具语句 适合Access和Mssql注入

    啊D注入工具中使用的SQL注入语句 爆user )) )= | ***** ?Id)) : ?Id : Id 检查SA权限:)))) 爆当前库: )) -- 检查是否为mssql数据库:and exi ...

  3. UIImageJPEGRepresentation和UIImagePNGRepresentation

    UIImageJPEGRepresentation方法在耗时上比较少 而UIImagePNGRepresentation耗时操作时间比较长 -(void)imagePickerController:( ...

  4. RDLC系列之四 常见错误

    解决 RDLC 报表自动分页表头显示问题 原文:http://www.th7.cn/Program/net/201207/85445.shtml RDLC是用XML来描述一个报表相关的一切,只需要在& ...

  5. R 分类进行数值处理

    主要Mark一下R程序中,分类进行数值计算的情况. 1.aggregate函数 有数据框case,列名分别a,b,c,d,e,f (1)根据一列对另一列求和:根据a,对d求和 sum1 <- a ...

  6. [转]20位活跃在Github上的国内技术大牛

    FROM : http://blog.csdn.net/yaoxtao/article/details/38518933 20位活跃在Github上的国内技术大牛 本文列举了20位在Github上非常 ...

  7. Linux Linux程序练习十(网络编程大文件发送)

    //网络编程客户端--大文件传输 #include <stdio.h> #include <stdlib.h> #include <string.h> #inclu ...

  8. C#事件与接口

    using System; namespace ConsoleApplication1d { delegate void MsgDel(string s); interface IMsg { even ...

  9. WorldWind源码剖析系列:WorldWind实时确定、更新、初始化和渲染地形和纹理数据

    WorldWind实时确定.更新.初始化和渲染地形和纹理数据 当用户点击WorldWind中的地球时,首先响应的是WorldWindow.OnPaint()函数,后续程序的调用流程如下图所示. 零散知 ...

  10. android背景选择器selector用法汇总

    一.创建xml文件,位置:drawable/xxx.xml,同目录下记得要放相关图片 <?xml version="1.0" encoding="utf-8&quo ...