「NOIP模拟赛」锻炼计划
身体是革命的本钱,OIers不要因为紧张的学习和整天在电脑前而忽视了健康问题。小x设计了自己的锻炼计划,但他不知道这个计划是否可行,换句话说如果计划不当可能会让他的体力超支,所以小x请你帮助他。
一天有1440分钟,所以小x列出的是这一整天第1至第1440分钟的计划。小x的体力用一个整数来表示,他会按照计划表进行锻炼,同时,每分钟小x的体力会自动增加1。如果某一分钟末小x的体力小于等于零,那么可怜的小x就累死了……
输入(exercise.in)
第一行是用空格分开的两个整数n,m,分别表示小x的初始体力值和计划的项目数量。
从第二行开始的m行,每行描述一个锻炼项目:名称、开始时间a、结束时间b、每分钟耗费的体力(用空格分隔),表示此项目从第a分钟初开始,第b分钟末结束。锻炼项目按照开始时间递增顺序给出,不会出现两个项目时间冲突的情况。
输出(exercise.out)
输出包括两行,如果计划可行,第一行输出”Accepted”,第二行输出这一天过后最后剩余的体力;否则在第一行输出”Runtime Error”,第二行输出在第几分钟累死。
样例
| Input | Output | 
| 10 1 Basketball 1 10 1 | Accepted 1440 | 
| 1 1 Nunchakus 1 1 2 | Runtime Error 1 | 
约定
0<n<=2^31-1
0<=m<=500
所有中间值的绝对值不会超过2^31-1
每一个锻炼项目的名称不超过20个字符,其中不含空格。
题解
数据很小直接模拟
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<map> #define ll long long  using namespace std; int read() {     int x=0,f=1;char ch=getchar();     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}     return x*f; } int n,m; int a[2005]; int main() { 	//freopen("exercise.in","r",stdin); 	//freopen("exercise.out","w",stdout); 	for(int i=1;i<=1440;i++)a[i]=1; 	n=read();m=read(); 	for(int i=1;i<=m;i++) 	{ 		char ch[25]; 		scanf("%s",ch); 		int l=read(),r=read(),v=read(); 		for(int j=l;j<=r;j++)a[j]-=v; 	} 	int sum=n; 	for(int i=1;i<=1440;i++) 	{ 		sum+=a[i];	 		if(sum<=0){printf("Runtime Error\n%d\n",i);return 0;} 	} 	puts("Accepted"); 	printf("%d",sum); 	return 0; } | 
                                  Subscribe  
                            
                                                                        
                    