今天晚上本希望参加提高组的模拟,但是提高组的发题的人迟到进3个小时,时间就是金钱啊,再说那样就太晚了,只得去参加今晚的普及组模拟赛,题目简单的不能再简单了,1个小时就搞定了
我的代码:
buy.c
#include<stdio.h>
int main(void)
{
int i,j,k;
int x,v,temp;
int c,n;
int countline[10001]={0};
FILE *input,*output;
input=fopen("buy.in","r");
utput=fopen("buy.out","w");
fscanf(input,"%d%d",&c,&n);
for(i=0;i<n;i++)
{
fscanf(input,"%d%d",&x,&v);
for(j=c;j>=x;j--)
{
if(countline[j]<(temp=(countline[j-x]+v)))
countline[j]=temp;
}
}
fprintf(output,"%d\n",countline[c]);
fclose(input);
fclose(output);
return 0;
}
day.c
#include<stdio.h>
int main(void)
{
int i,j,k,x,y,z;
int m[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int y1,y2,m1,m2,d1,d2;
int sum=0;
FILE *input,*output;
input=fopen("day.in","r");
utput=fopen("day.out","w");
fscanf(input,"%d%d%d%d%d%d",&y2,&m2,&d2,&y1,&m1,&d1);
for(i=y1;i<y2;i++)
{
if(i%4) x=365; else x=366;
sum+=x;
}
for(i=0;i<m2-1;i++)
sum+=m[i];
if(y2%4==0 && m2>2) sum++;
sum+=d2;
for(i=0;i<m1-1;i++)
sum-=m[i];
if(y1%4==0 && m1>2) sum--;
sum-=d1;
fprintf(output,"%d\n",sum);
fclose(input);
fclose(output);
return 0;
}
present.c
#include<stdio.h>
typedef struct
{
int num; /*编号*/
int x; /*分数*/
} DATA;
DATA data[100];
int x,y;
int n;
FILE *input,*output;
/*Qsort!*/
void qsort(int low,int high,DATA key[])
{
int i=low,j=high;
DATA tag;
if(i<j)
{
tag=key[i];
do
{
while(((tag.x>key[j].x)||(tag.x==key[j].x && tag.num<=key[j].num)) && i<j) j--;
if(i<j)
{
key[i]=key[j];
i++;
while(((tag.x<key[i].x)||(tag.x==key[i].x && tag.num>key[i].num)) && i<j) i++;
if(i<j)
{
key[j]=key[i];
j--;
}
}
}while(i<j);
key[i]=tag;
qsort(low,j-1,key);
qsort(i+1,high,key);
}
}
/*I want to fly higher!*/
int main(void)
{
int i,j,k;
input =fopen("present.in","r");
utput=fopen("present.out","w");
fscanf(input,"%d",&n);
for(i=0;i<n;i++)
fscanf(input,"%d%d",&data[i].num,&data[i].x);
qsort(0,n-1,data);
for(i=0;i<n;i++)
fprintf(output,"%d %d %d\n",i+1,data[i].num,data[i].x);
fclose(input);
fclose(output);
return 0;
}
save.c
#include<stdio.h>
int main(void)
{
int i,j,k;
int n;
int x,y;
int sum=0;
FILE *input,*output;
input=fopen("save.in","r");
utput=fopen("save.out","w");
fscanf(input,"%d",&n);
for(i=0;i<n;i++)
{
fscanf(input,"%d%d",&x,&y);
sum=sum+x-y;
}
if(sum>0)
{
fprintf(output,"Yes\n%d\n",sum);
}
else
{
fprintf(output,"No\n");
}
fclose(input);
fclose(output);
return 0;
}
2关键字排序+DP基础(0/1背包)+简单模拟
数据规模相当小,搜有时可能都比DP快...