ZOJ1246 POJ1472 HDU1468 Instant Complexity
来源:互联网 发布:国外域名注册网站 编辑:程序博客网 时间:2024/06/01 10:26
很烦躁的题, 不管是输入还是输出, 都给人奔溃的感觉
用递归吧, 设个临时数组保存子循环的时间复杂度
#ifdef _MSC_VER#define DEBUG#define _CRT_SECURE_NO_DEPRECATE#endif#include <fstream>#include <stdio.h>#include <iostream>#include <string.h>#include <string>#include <limits.h>#include <algorithm>#include <math.h>#include <numeric>#include <functional>#include <ctype.h>#define MAX 20using namespace std;int order[1000][2];void func(const int &beg,const int &end,int *num){for(int i=beg;i<end;){if(order[i][0]==3){num[0]+=order[i][1];++i;}else if(order[i][0]==2){int temp[20];memset(temp,0,sizeof(temp));int sum=1;int t=i+1;while(sum){if(order[t][0]==2)++sum;else if(order[t][0]==1)--sum;++t;}func(i+1,t-1,temp);if(order[i][1]==INT_MAX)for(int j=0;j<MAX-1;++j)num[j+1]+=temp[j];elsefor(int j=0;j<MAX;++j)num[j]+=temp[j]*order[i][1];i=t;}}}int main(void){#ifdef DEBUG freopen("../stdin.txt","r",stdin); freopen("../stdout.txt","w",stdout); #endif string str,cost;int ncases;scanf("%d",&ncases); cin>>str;for(int nc=1;nc<=ncases;++nc){int n=0; int sum=1;while(sum){if(str=="BEGIN" )order[n++][0]=0;else if(str=="END") { order[n++][0]=1; --sum; }else {cin>>cost;int temp;if(cost=="n")temp=INT_MAX;elsetemp=atoi(cost.c_str());if(str=="LOOP") {order[n][0]=2; ++sum; }else {order[n][0]=3; }order[n++][1]=temp;} cin>>str;}int ans[MAX];memset(ans,0,sizeof(ans));func(1,n-1,ans);printf("Program #%d\nRuntime =",nc); bool flag=false; for(int i=MAX-1;i>1;--i) if(ans[i]>1) { printf("%c%d*n^%d",flag?'+':' ',ans[i],i); flag=true; } else if(ans[i]==1) { printf("%cn^%d",flag?'+':' ',i); flag=true; } if(ans[1]>1) { printf("%c%d*n",flag?'+':' ',ans[1]); flag=true; } else if(ans[1]) { printf("%cn",flag?'+':' '); flag=true; } if(ans[0]) { printf("%c%d",flag?'+':' ',ans[0]); flag=true; } if(!flag) printf(" 0"); printf("\n\n");} return 0;}
- ZOJ1246 POJ1472 HDU1468 Instant Complexity
- POJ1472浅析------Instant Complexity
- poj1472--Instant Complexity(模拟)
- Instant Complexity - POJ1472
- Instant Complexity poj1472 (递归模拟)
- Instant Complexity
- pku 1472 Instant Complexity
- Poj 1472 Instant Complexity
- POJ 1472 Instant Complexity
- uva 586 Instant Complexity
- UVA 586 Instant Complexity
- POJ 1472 Instant Complexity
- POJ 1472 Instant Complexity
- UVA - 586 Instant Complexity
- ZOJ 1246 Instant Complexity
- 【POJ】 Instant Complexity (模拟)
- Poj 1472 Instant Complexity
- poj-1472 Instant Complexity
- 青玉案-元夕
- 生成验证码图片
- 王利芬的经典语录
- ASP.NET多线程下载
- 获取缓冲区的大小
- ZOJ1246 POJ1472 HDU1468 Instant Complexity
- 爱的教育
- vi命令一览表
- Flex+J2EE实例(cairngorm+blazeDS+hibernate+spring) part3
- Android权限大全代码
- Qt4 SDK(mingw编译版)与VS2008/VS2005的集成开发环境的安装配置
- 收缩SqlServer 2008数据库日志
- PCB units conversion
- 模块化CSS的一些看法