[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 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...
随机推荐
- 迷你DVD管理器项目
package chapter5; import java.util.*; public class MiniDVD { public static void main(String[] args){ ...
- python playfair
#########################Playfair密码######################### #约定1:若明文字母数量为奇数,在明文末尾添加一个'Z' #约定2:'I'作为 ...
- [Elixir009]像GenServer一样用behaviour来规范接口
1.Behaviour介绍 Erlang/Elixir的Behaviour类似于其它语言中的接口(interfaces),本质就是在指定behaviours的模块中强制要求导出一些指定的函数,否则编译 ...
- 验证视图状态 MAC 失败的解决办法
昨天用户反应系统中有问题,问题就在于翻页的时候,系统会报以下错误.但是我们的系统已经上线1年多了,从来没出现过错误,怎么会出现错误呢?于是开始检测,查找原因. 1. 出错提示 “/”应用程序中的服务器 ...
- SgmlReader使用方法
HtmlAgilityPack是一个开源的html解析器,底层是通过将html格式转成标准的xml格式文件来实现的(使用dot net里的XPathDocument等xml相关类),可以从这里下载:h ...
- python中class 的一行式构造器
好处:避免类初始化时大量重复的赋值语句 用到了魔法__dict__ # 一行式构造器 class Test(): # 初始化 def __init__(self, a, b, c=2, d=3, e= ...
- GridView自定义分页
CSS样式 首先把CSS样式代码粘贴过来: .gv { border: 1px solid #D7D7D7; font-size:12px; text-align:center; } .gvHeade ...
- CSS 实现加载动画之二-圆环旋转
上次简单的介绍了下如何用代码实现菊花旋转的加载动画,动画点击,这次继续我们的动画系列,实现另外一种加载动画,圆环旋转.与上次不同的是,菊花旋转是通过改变元素透明度来实现动画,这次因为考虑到元素叠加,加 ...
- Caffe学习系列(16):caffemodel可视化
通过前面的学习,我们已经能够正常训练各种数据了.设置好solver.prototxt后,我们可以把训练好的模型保存起来,如lenet_iter_10000.caffemodel. 训练多少次就自动保存 ...
- [CareerCup] 1.2 Reverse String 翻转字符串
1.2 Implement a function void reverse(char *str) in C or C++ which reverses a null-terminated string ...