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

一开始我能得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. jQuery——切换toggle

    toggle()-----显示隐藏 toggleClass-------添加类或者删除类 <!DOCTYPE html> <html lang="en"> ...

  2. [Windows Server 2012] 安装护卫神·主机管理系统

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装护卫神·主 ...

  3. iframe监听unload事件

    阻止默认事件 event.preventDefault(); 阻止事件冒泡 event.stopPropagation(); event.cancelBubble = true; //IE <a ...

  4. block要用copy修饰,还是用strong

    栈区与堆区 block本身是像对象一样可以retain,和release.但是,block在创建的时候,它的内存是分配在栈(stack)上,而不是在堆(heap)上.他本身的作于域是属于创建时候的作用 ...

  5. 不用float也可以让div横向显示

    display: inline-block; vertical-align: top; 就这两个属性,给div设置上,div就不会换行显示啦,而且还不影响横向的其他元素的显示.

  6. Python虚拟环境和requirements.txt文件的使用

    参考: https://www.centos.bz/2018/05/centos-7-4-%E5%AE%89%E8%A3%85python3%E5%8F%8A%E8%99%9A%E6%8B%9F%E7 ...

  7. linux搭建mysql服务器及可视化工具

    环境: ubutnu 18.4 mysql 5.7 参考: 安装 https://www.cnblogs.com/opsprobe/p/9126864.html 配置用户权限 https://baij ...

  8. CDR真实图片转水墨画效果制作教程

    CorelDRAW创造性滤镜组是最具有创造力的滤镜,使用里面的散开滤镜能够实现类似于水墨的表现手法,然后再结合图层的合并模式,让您的图片产生意想不到的视觉效果.本文将利用CorelDRAW软件中提供的 ...

  9. CAD全屏显示控件

    主要用到函数说明: MxDrawXCustomFunction::Mx_FullScreen 全屏显示控件,详细说明如下: 参数 说明 int iFull = 2 0: 不完屏,1:全屏,2:自动切换 ...

  10. zabbix_agent自动发现服务端口

    应用背景:       zabbix监控系统介绍及安装,参考大牛运维生存时间,在这儿就不啰嗦了 为了zabbix-agent端能自动把服务器端的服务端口汇报给 zabbix server端,监控其端口 ...