这是我今天遇到最奇怪的问题,希望有人帮我解释一下。。。

一开始我能得90分:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
typedef long long ll;
const int INF = << ;
const ll mod = ; typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
ll n,s = ;
ll p[],x,ans = ;
ll num = ;
int main()
{
read(n);
duke(i,,n)
{
read(x);
if(x == )
{
p[++num] = x;
}
else
{
s = ;
while (p[num] != )
{
s += p[num];
s = s % mod;
num--;
}
if(s == )
{
p[num] = ;
}
else
{
p[num] = s * % mod;
}
}
}
ll tot = ;
duke(i,,num)
{
// cout<<p[i]<<endl;
tot += p[i];
tot %= mod;
}
write(tot);
return ;
}

然而并不知道为什么。。。找了个题解,发现没啥区别,然后就改了一下num的顺序,结果变成80,最神奇的是之前错的那个点对了,然而另两个点错了。。。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
typedef long long ll;
const int INF = << ;
const ll mod = ;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
ll n,s = ;
ll p[],x,ans = ;
ll num = ;
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
read(n);
p[] = ;
p[] = ;
clean(p);
duke(i,,n)
{
read(x);
if(x == )
{
p[num++] = x;
}
if(x == )
{
s = ;
while (p[num - ] != )
{
s += p[num - ];
s = s % mod;
num--;
}
/*if(i == n)
{
printf("%lld\n",s);
cout<<num - 1<<endl;
}*/
if(s == )
{
p[num - ] = ;
}
else
{
p[num - ] = (s * ) % mod;
}
/*if(i == n)
{
printf("%lld\n",p[num - 1]);
cout<<num - 1<<endl;
}*/
}
}
ll tot = ;
duke(i,,num - )
{
// cout<<p[i]<<endl;
tot += p[i];
tot %= mod;
}
write(tot);
return ;
}

蒙了,然后一点点de,到最后也没看出来。通过一些手段发现了是算和的时候出问题了,然而并不知道为什么。。。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
typedef long long ll;
const int INF = << ;
const ll mod = ;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
ll n,s = ;
ll p[],x,ans = ;
ll num = ;
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
read(n);
p[] = ;
p[] = ;
clean(p);
duke(i,,n)
{
read(x);
if(x == )
{
p[num] = x;
num++;
}
if(x == )
{
s = ;
while (p[num - ] != )
{
s += p[num - ];
s = s % mod;
num--;
}
if(s == )
{
p[num - ] = ;
}
else
{
p[num - ] = (s * ) % mod;
}
}
}
for(int i=;i<num;i++)
{
// cout<<p[i]<<endl;
p[] += p[i];
p[] = p[] % ;
}
cout<<p[];
return ;
}
/*
6
0
0
1
1
0
1
( ( ) ) ( )
0 0 1 2 0 1
*/

就是把

ll tot = ;
duke(i,,num - )
{
// cout<<p[i]<<endl;
tot += p[i];
tot %= mod;
}
write(tot);

换成

for(int i=;i<num;i++)
{
// cout<<p[i]<<endl;
p[] += p[i];
p[] = p[] % ;
}
cout<<p[];

就对了!!!震惊!!!为什么?求大佬解释。。。

B3300 [USACO2011 Feb]Best Parenthesis 模拟的更多相关文章

  1. BZOJ3300: [USACO2011 Feb]Best Parenthesis 模拟

    Description Recently, the cows have been competing with strings of balanced  parentheses and compari ...

  2. BZOJ3300: [USACO2011 Feb]Best Parenthesis

    3300: [USACO2011 Feb]Best Parenthesis Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 42 ...

  3. 【BZOJ】3300: [USACO2011 Feb]Best Parenthesis(模拟)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3300 这个细节太多QAQ 只要将所有的括号'('匹配到下一个')'然后dfs即可 简单吧,,, #i ...

  4. [USACO2011 Feb]Best Parenthesis

    Time Limit: 10 Sec Memory Limit: 128 MB Description Recently, the cows have been competing with stri ...

  5. 3301: [USACO2011 Feb] Cow Line

    3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 82  Solved: 49[Submit ...

  6. 【BZOJ】【3301】【USACO2011 Feb】Cow Line

    康托展开 裸的康托展开&逆康托展开 康托展开就是一种特殊的hash,且是可逆的…… 康托展开计算的是有多少种排列的字典序比这个小,所以编号应该+1:逆运算同理(-1). 序列->序号:( ...

  7. BZOJ2274: [Usaco2011 Feb]Generic Cow Protests

    2274: [Usaco2011 Feb]Generic Cow Protests Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 196  Solve ...

  8. BZOJ3301: [USACO2011 Feb] Cow Line

    3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 67  Solved: 39[Submit ...

  9. 2272: [Usaco2011 Feb]Cowlphabet 奶牛文字

    2272: [Usaco2011 Feb]Cowlphabet 奶牛文字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 138  Solved: 97 ...

随机推荐

  1. 正则表达式提取String子串

    最近遇到了一个字符串处理的功能,忽然发现了正则表达式的强大,深深的被她的迷人魅力所吸引,以前只是听说,今天亲眼所见,亲身经历,真的彻底折服. 言归正传:java中String类里面封装了很多字符串处理 ...

  2. Ubuntu 18.04 如何固定图标到任务栏

    参考 https://blog.csdn.net/u014160286/article/details/81631863

  3. kswapd和pdflush

    首 先,它们存在的目的不同,kswap的作用是管理内存,pdflush的作用是同步内存和磁盘,当然因为数据写入磁盘前可能会换存在内存,这些缓存真正写 入磁盘由三个原因趋势:1.用户要求缓存马上写入磁盘 ...

  4. DNS详细解析过程【转】

    转自:http://blog.csdn.net/crazw/article/details/8986504 先说一下DNS的几个基本概念: 一. 根域 就是所谓的“.”,其实我们的网址www.baid ...

  5. enote笔记语言(3)

    what&why(why not)&how&when&where&which:紫色,象征着神秘而又潜蕴着强大的力量,故取紫色. key&key-memo ...

  6. 2977,3110 二叉堆练习1,3——codevs

    二叉堆练习1 题目描述 Description 已知一个二叉树,判断它是否为二叉堆(小根堆) 输入描述 Input Description 二叉树的节点数N和N个节点(按层输入) 输出描述 Outpu ...

  7. SOUI界面库 添加 windows系统文件图标皮肤

    最近在学习soui界面库.其中有用到SListCtrl这个控件来现在文件信息.控件用法基本上和mfc 的CListCtrl差不多.也支持图标显示.但是图标是要自己加入图标图片的.这个就有点不好弄.于是 ...

  8. Linux之网络文件共享服务(NFS)

    概念: NFS:Network File System 网络文件系统,基于内核的文件系统.Sun公司开发,通过使用NFS,用户和程序可以像访问本地文件一样访问远端系统上的文件,基于RPC(Remote ...

  9. chromeDriver下载地址

    http://chromedriver.storage.googleapis.com/index.html

  10. (43). Spring Boot动态数据源(多数据源自动切换)【从零开始学Spring Boot】

    在上一篇我们介绍了多数据源,但是我们会发现在实际中我们很少直接获取数据源对象进行操作,我们常用的是jdbcTemplate或者是jpa进行操作数据库.那么这一节我们将要介绍怎么进行多数据源动态切换.添 ...