[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 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...
随机推荐
- javascript中的array对象属性及方法
Array 对象 Array 对象用于在单个的变量中存储多个值. 创建 Array 对象的语法: new Array(); new Array(size); new Array(element0, e ...
- page-cache层以及各种标志位之间的转换
对真实文件系统层,算是懂了,但是vfs层以及block层还是有点生疏呢,最近要好好分析一下了. page-cache层主要关注文件读写时的行为,包括页的状态之间的变化,何时变脏,何时变成writeba ...
- 第二章 rabbitmq在mac上的安装
下载页: http://www.rabbitmq.com/install-standalone-mac.html 1.下载页面首部的文件(页面下载可能比较慢,使用迅雷下载就好),之后解压到一个合适的路 ...
- C#属性有什么作用
1,主要作用:将读,写权限分开.如果不使用属性,仅使用public, protected, private,这几个限制都是读,写属性一起的,可读就可写,不可读同时也不可写.不能实现只读不可写,只写不可 ...
- MySQL基础 - 外键和约束
在工作中经常会遇到不少不同的观点,比如对于数据库来说那就是是否要设置外键,设置外键的理由自然不必多说,而不设置外键的理由多半为设置外键影响性能,但就目前工作来讲,还没有涉及到因为外键而引发的数据库瓶颈 ...
- Caffe学习系列(19): 绘制loss和accuracy曲线
如同前几篇的可视化,这里采用的也是jupyter notebook来进行曲线绘制. // In [1]: #加载必要的库 import numpy as np import matplotlib.py ...
- WebSocket 服务器3
其实,在服务器的选择上很广,基本上,主流语言都有WebSocket的服务器端实现,而我们作为前端开发工程师,当然要选择现在比较火热的NodeJS作为我们的服务器端环境了.NodeJS本身并没有原生的W ...
- GDB堆栈跟踪与汇编调试
GDB堆栈跟踪与汇编调试 堆栈跟踪 源代码: 对预先编写的 stack.c 文件进行编译,并且使用 CGDB 进行调试,对堆栈进行跟踪,了解该代码堆栈是如何变化的. 在 CGDB 中,先设置 main ...
- c#中的var优缺点和适用场景
var是c# 3.0新加的特性,叫做隐式类型局部变量,大家都知道c#其实是一种强类型的语言,为什么会引入匿名类型呢? 我猜测是因为linq的原因吧,因为感觉var在linq中被大量使用.下面说下var ...
- openssl实践总结
openssl实验总结 OPENSSL简介 OpenSSL项目是一个协作开发一个健壮的,商业级的,全功能的,并且开放源代码工具包,它实现了安全套接字层(SSL v2/v3)和传输层安全(TLS v1) ...