1.http://www.rqnoj.cn/problem/1
program mingming; var a:array [1..1000] of integer; i,j,k,n:longint; begin fillchar(a,0,sizeof(a)); k:=0; read(n); for i:=1 to n do begin read(j); if a[j] <> 1 then begin a[j]:=1; inc(k); end; end; writeln(k); for i:=1 to 1000 do begin if a[i] = 1 then write(i,' '); end; end.
2.
#include <stdio.h> #define maxm 26 #define maxn 30001 int n,m; int v[maxm],w[maxm]; int f[maxn]={0}; int main(int argc, const char *argv[]) { // freopen("1.in","r",stdin); int i,j,k,l; scanf("%d%d",&n,&m); for(i=1;i<=m;i++) scanf("%d%d",&v[i],&w[i]); for(i=1;i<=m;i++) for(j=n;j>0;j--) { if(j>=v[i] && (f[j] < f[j-v[i]] + v[i]*w[i])) f[j] = f[j- v[i]] + v[i]*w[i]; } printf("%d",f[n]); return 0; }
3.
#include <stdio.h> #include <stdlib.h> char JamNum[27]={0}; char Snum[27]= {0}; int weishu,Start,End; int main() { char Schar,Echar,temp; int change; int i,j,k,l; scanf("%d%d%d",&Start,&End,&weishu); scanf("%s",Snum); //printf("%s",Snum); Schar=Start+'a'-1;Echar=End+'a'-1; //printf("%c %c",Schar,Echar); for(j=0;j<5;j++) { change = 26; for(i=weishu-1;i>=0;i--)//判断那一位可以改 { if(Snum[i]<Echar+i-weishu+1) { change=i; break; } } if(change == 26) return 0; temp=Snum[change]; for(i=change;i<weishu;i++) { Snum[i]=++temp; } printf("%s ",Snum); } return 0; }
4.
#include <stdio.h> #define maxn 1000 int f[1001]= {1,1}; int k,N; int pow(int a,int b) { int r= 1,base = a; while(b != 0) { if(b&1) r*= base; base *= base; b>>=1; } return r; } int main(int argc, const char *argv[]) { int i,j,l,temp,temp2; scanf("%d%d",&k,&N); l=1; j=2; // temp = pow(N,l); temp =2; for(i=2;i<N+1;i++) { if(j < temp ){ f[i] =temp2 + f[j++]; } else { temp2 = f[i] = pow(k,l++); j=1,temp = i; } } printf("%d",f[N]); return 0; }
5.
/* * ===================================================================================== * * Filename: pid5.c * * Description: PID5/能量项链 * * Version: 1.0 * Created: 2014-9-23 17:31:43 * Revision: none * Compiler: gcc * * Author: Rainboy (mn), 597872644@qq.com * Company: NONE * * ===================================================================================== */ #include <stdio.h> #define maxn 1000 int f[301][301]= {0}; int N; int u[301],v[301]; int main(int argc, const char *argv[]) { freopen("energy.in","r",stdin); freopen("energy.out","w",stdout); int i,j,k,l; scanf("%d",&N); scanf("%d",&i); u[1] = i; v[N] = i; for(i=2;i<N+1;i++) { scanf("%d",&j); u[i]= j; v[i-1]=j; } for(i=N+1;i<2*N;i++) { u[i]= u[i-N]; v[i] = v[i-N]; } for(i=1;i<N+1;i++) for(l=1;l<N;l++)//宽度 for(j=i;j<N+i;j++) for(k=j;k+1<=j+l;k++) { if(f[j][j+l] < f[j][k]+f[k+1][j+l] + u[j]*v[k]*v[j+l]) f[j][j+l] = f[j][k]+f[k+1][j+l] + u[j]*v[k]*v[j+l]; } l = 0; for(i=1;i<N+1;i++) if(l<f[i][i+N-1] ) l=f[i][i+N-1]; printf("%d",l); return 0; }
6.
/* * ===================================================================================== * * Filename: 6.c * * Description: 金明的预算方案 * * Version: 1.0 * Created: 2014-9-24 12:37:55 * Revision: none * Compiler: gcc * * Author: Rainboy (mn), 597872644@qq.com * Company: NONE * * ===================================================================================== */ #include <stdio.h> int N,m; #define maxn 200 //有附件的只是有多种选择而已,不买,买主件,买主件+附件1,买主件+附件2,等等 共有4种可能性 //所以我们只处理我们的数据结构就行了 //每个主件最多有2个附件 让这一题的难度降低很多 int f[maxn][maxn] ={0}; int val[maxn][maxn] = {0}; int ans[32001]= {0}; int main(int argc, const char *argv[]) { int i,j,k,l,v,p,q; scanf("%d%d",&N,&m); for(i=1;i<=m;i++) { scanf("%d%d%d",&v,&p,&q); if(q == 0) { f[i][1] = v; val[i][1] = p; ++f[i][0]; } else { f[q][++f[q][0]]= v; val[q][f[q][0]] = p; } } for(i=1;i<=m;i++) { if(f[i][0] !=0 ) { for(j=N;j>0;j--) // 判断 附件有多少 0-1-2 { if(j-f[i][1] >=0 && ans[j] < f[i][1]*val[i][1] + ans[(j-f[i][1])] ) ans[j] = f[i][1]*val[i][1] + ans[(j-f[i][1])];// 只买主件 if(f[i][0] >1)// 买主件 + 附件1 { if(j-f[i][1]-f[i][2] >=0 && ans[j] < f[i][1]*val[i][1] + f[i][2]*val[i][2] +ans[(j-f[i][1]-f[i][2])]) ans[j] = f[i][1]*val[i][1] + f[i][2]*val[i][2] +ans[(j-f[i][1]-f[i][2])]; if(f[i][0] == 3) {//买附件2 + 主件 if(j-f[i][1] - f[i][3] >=0 && ans[j] < f[i][1]*val[i][1] + f[i][3]*val[i][3] + ans[(j-f[i][1] - f[i][3])]) ans[j] < f[i][1]*val[i][1] + f[i][3]*val[i][3] + ans[(j-f[i][1] - f[i][3])] ; //买附件1+2+主件 if(j-f[i][1] - f[i][2] -f[i][3] >= 0 && ans[j] < f[i][1]*val[i][1] + f[i][2] * val[i][2] + f[i][3]*val[i][3] + ans[(j-f[i][1] - f[i][2] - f[i][3])]) ans[j] = f[i][1]*val[i][1] + f[i][2] * val[i][2] + f[i][3]*val[i][3] + ans[(j-f[i][1] - f[i][2] - f[i][3])]; } } } } } printf("%d",ans[N]); return 0; }
7. 题目的描述真的太长了,这个题目的难度就在于他的长度。看来功夫在诗外啊,如果NOIP出一题阅读时间超长的题,30分钟,绝对是前10难度;
/* * ===================================================================================== * * Filename: 7-2.c * * Description: PID7 * * Version: 1.0 * Created: 2014-9-25 16:48:22 * Revision: none * Compiler: gcc * * Author: Rainboy (mn), 597872644@qq.com * Company: NONE * * ===================================================================================== */ #include <stdio.h> int jiqi[21][21];// 第i 个工件 第j步用的机器 int gongxu[500]; // 判断工件 是哪个工序 int gongxuf[500]= {0};// 辅助 int time[21][21];// 工序用的时间 int xl[500];// 输入的工件序列 int bool[21][1000] = {0}; int finishTime[21] ={0}; // 工件 前一个工序结束的时间 int n,m; int main(int argc, const char *argv[]) { int i,j,k,l; int t,temp,mc; scanf("%d%d",&m,&n);//m-机器数 n-工件数 for(i=1;i<=m*n;i++) { scanf("%d",&j); xl[i] = j; gongxu[i] = ++gongxuf[j]; } for(i=1;i<=n;i++) for(j=1;j<=m;j++) scanf("%d",&jiqi[i][j]); for(i=1;i<=n;i++) for(j=1;j<=m;j++) scanf("%d",&time[i][j]); for(i=1;i<=m*n;i++) { t = xl[i];// t 表示现在要加入的工件的编号 j = finishTime[t]; // j 表示工件上一步结束的时间 mc = jiqi[t][gongxu[i]];// mc 表示 用到的机器 // 下面的就是进行 见缝插针 temp = 0; for(k=j+1;;k++) { if(bool[mc][k] == 0) { if( ++ temp == time[t][gongxu[i]]) { bool[mc][0] = bool[mc][0] > k ? bool[mc][0]: k; finishTime[t] = k; for(l=k- time[t][gongxu[i]] +1;l<=k;l++) bool[mc][l] = 1; break; } } else temp = 0; } } temp =0; for(i=1;i<=m;i++) if(temp < bool[i][0]) temp = bool[i][0]; printf("%d",temp); return 0; }