hdu 4891 The Great Pan
来源:互联网 发布:linux 查看外网ip地址 编辑:程序博客网 时间:2024/04/24 03:08
题目链接:点击打开链接
模拟字符串水题。
题意 一对{}之间若有n个|则有n+1种可能性,两个$$间有n段连续的空格则有每段空格长度+1再乘到一起种可能,结果是所有可能相乘,超过1e5输出doge
读成一个长字符串就好处理了,可用
long long cur=0;
for(int i=0;i<n;i++){
gets(a+cur);
cur+=strlen(cur+a);
}
无需使用第二个字符串
坑在于可能性不但会爆int 还会爆long long!$的情况虽然考虑到最终结果会爆,但是没想到表示当前可能性的中间结果也会爆,wa了n次
代码:
#include <iostream>#include <cstring>#include <cstdio>using namespace std;char a[1024*1024+10];char t[1024*1024+10];void input(int n){ memset(a,0,sizeof(a)); long long cur=0; for(int i=0;i<n;i++){ gets(a+cur); cur+=strlen(cur+a); }}int main(){ int n; while(scanf("%d%*c",&n)!=EOF){ input(n); bool x=0; bool y=0; long long n1=1; long long n2=1; long long res=1; long long len=strlen(a); long long t=1; for(int i=0;i<len;i++){ if(x){ if(a[i]=='|')n1++; if(a[i]=='}'){ res*=n1; n1=1; x=0; if(res>100000){ res=-1; break; } } } else if(y){ if(a[i]==' ') t++; if(a[i]!=' '){ n2*=t; t=1; if(n2>1e5){ res=-1; break; } } if(a[i]=='$'){ res*=n2; y=0; n2=1; if(res>100000){ res=-1; break; } } } else if(a[i]=='{') x=1; else if(a[i]=='$') y=1; } if(res==-1) printf("doge\n"); else printf("%I64d\n",res); } return 0;}
0 0
- Hdu 4891 The Great Pan
- HDU 4891 The Great Pan
- hdu 4891 The Great Pan
- HDU 4891 The Great Pan
- hdu 4891 The Great Pan
- hdu 4891 The Great Pan(模拟)
- HDU 4891 The Great Pan(模拟)
- hdu 4891 The Great Pan(模拟)
- hdu 4891 The Great Pan (模拟)
- HDU 4891 The Great Pan (模拟)
- HDU 4891 The Great Pan(模拟)
- HDU 4891 The Great Pan (字符串处理)
- HDU--4891--The Great Pan--暴力搜索
- HDU 4891— The Great Pan
- HDU 4891 The Great Pan 模拟
- 【HDU 4891 多校联合】The Great Pan【模拟】
- hdu 4891 The Great Pan 字符串的处理
- HDU 4891 The Great Pan 解题报告(水题)
- hdu1342
- 【转】POJ 3264 线段树解法
- cocos2dx 3.x Button的认识
- MFC中修改对话框ID时,向导中无法显示所有的控件ID
- Java多线程之任务执行架构
- hdu 4891 The Great Pan
- 苹果官方文档:理解和分析ios应用崩溃日志
- NYOJ206---求余数
- Java Servlet Specification 3.0之回顾
- linux内核链表分析
- Java多线程之Exchanger
- Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱
- [Oracle|MySQL]数据库时间类型
- hdu_1799_循环多少次_201407311017