hdu 4891---水题 但是WA了很多次
2014-07-29 20:14
344 查看
这道题的坑在----过程中即使使用long long 也会超出范围
自己看了很久读了很多遍题还是没想到
记得当时的想法是----反正我用了long long 已经是最大的范围了,肯定没法用更大的类型--即使unsigned也只是 比long long 大一倍,现在回头看,这种想法太唯心,不是理性分析的结果啊,,
代码:
//1005
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
using namespace std;
#define ll long long
const ll lim=1e5;
int main()
{
//freopen("hdu1005.txt","r",stdin);
ll cnt,ans,kr,sp,n;
char c;
int last;
bool flag=0;
while(~scanf("%I64d",&n))
{
flag=0;
getchar();
cnt=kr=sp=0;
ans=1;
while(1)
{
c=getchar();
if(c == '\n')cnt++;
if(cnt>=n || c==EOF)break;
//{}
if(c == '$')
{
kr=last=0;
while(1)
{
c=getchar();
if(c == '\n'){cnt++;if(kr)last=1;continue;}
if(c == ' ')kr++;
//if(c != ' ' && c == '\n')conti
if(c != ' ' && kr){if(ans>lim)flag=1;ans*=(kr+1);kr=0;}
if(c == '$')break;
}
if(c != ' ' && kr){if(ans>lim)flag=1;ans*=(kr+1);kr=0;}
////
}
if(c == '{')
{
sp=0;
while(1)
{
c=getchar();
if(c == '\n'){cnt++;}
if(c == '|'){sp++;}
if(c == '}')break;
}
if(ans>lim)flag=1;
ans*=(sp+1);
sp=0;
}
}
if(ans>lim||flag)printf("doge\n");
else printf("%I64d\n",ans);
}
return 0;
}
自己看了很久读了很多遍题还是没想到
记得当时的想法是----反正我用了long long 已经是最大的范围了,肯定没法用更大的类型--即使unsigned也只是 比long long 大一倍,现在回头看,这种想法太唯心,不是理性分析的结果啊,,
代码:
//1005
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
using namespace std;
#define ll long long
const ll lim=1e5;
int main()
{
//freopen("hdu1005.txt","r",stdin);
ll cnt,ans,kr,sp,n;
char c;
int last;
bool flag=0;
while(~scanf("%I64d",&n))
{
flag=0;
getchar();
cnt=kr=sp=0;
ans=1;
while(1)
{
c=getchar();
if(c == '\n')cnt++;
if(cnt>=n || c==EOF)break;
//{}
if(c == '$')
{
kr=last=0;
while(1)
{
c=getchar();
if(c == '\n'){cnt++;if(kr)last=1;continue;}
if(c == ' ')kr++;
//if(c != ' ' && c == '\n')conti
if(c != ' ' && kr){if(ans>lim)flag=1;ans*=(kr+1);kr=0;}
if(c == '$')break;
}
if(c != ' ' && kr){if(ans>lim)flag=1;ans*=(kr+1);kr=0;}
////
}
if(c == '{')
{
sp=0;
while(1)
{
c=getchar();
if(c == '\n'){cnt++;}
if(c == '|'){sp++;}
if(c == '}')break;
}
if(ans>lim)flag=1;
ans*=(sp+1);
sp=0;
}
}
if(ans>lim||flag)printf("doge\n");
else printf("%I64d\n",ans);
}
return 0;
}
相关文章推荐
- hdu 2539 虽然是水题 wa了很多次 说明自己的基本功不扎实 需要打好基础先 少年
- HDU 4379 水题,大水,但我WA了很多次,做了很久
- hdu 4891---水的问题 但WA非常多
- HDU-1093-A+B for Input-Output Practice (V)(水题也WA?)
- HDU 1017A Mathematical Curiosity 水题 WA了6次
- hdu 2955 水题却wa几次值得反思
- HDU - 2091 空心三角形 水题,但是有点坑...
- HDU4891_The Great Pan_字符串水题
- hdu 5038 水题 但是题意坑
- HDU 4891 The Great Pan 解题报告(水题)
- hdu 4891 模拟水题
- hdu 4891 模拟水题
- hdu 1256. 画八。。一直WA。后来才发现最后的空行错了,还有就是函数的,类型错了,要吸取教训啊。。
- 2014多校第三场1005 || HDU 4891 The Great Pan(模拟)
- hdu 4891 The Great Pan(模拟)
- hdu 1045 || zoj 1002 Fire Net(搜索:DFS+水题)
- HDU 5112 A Curious Matt 水题
- HDU 4891 The Great Pan (字符串处理)
- HDU 5461 Largest Point(2015沈阳赛区网络赛+技巧水题)
- Text Reverse hdu1062 水题