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

一开始我能得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. 如何在Linuxt系统下运行maven项目

    如何在Linuxt系统下运行maven项目 我们知道现在利用MAVEN来管理JAVA项目是非常常见的.比如公司一般都有一个自己的MAVEN仓库,通过MAVEN仓库来解决我们的项目依赖,更加方便的构建项 ...

  2. ipc (进程间通信

    进程间通信(IPC,Inter-Process Communication),指至少两个进程或线程间传送数据或信号的一些技术或方法.进程是计算机系统分配资源的最小单位(严格说来是线程).每个进程都有自 ...

  3. css nth-child 的应用

    最近改视频监控页面,由于窗口比较多,以前是通过计算窗口大小位置来处理页面布局的,其实还是比较麻烦,而且偶尔会有页面位置错乱的现象,虽然只是及其偶尔的现象,但总归是不好. 计算窗口位置的代码: /*监控 ...

  4. WPF在win7运行时报'Initialization of 'System.Windows.Setter' threw an exception.'

    写的一个WPF程序,在win10运行好好的,在win7就报'Initialization of 'System.Windows.Setter' threw an exception.' 原来是xaml ...

  5. 多目标跟踪笔记一:Finding the Best Set of K Paths Through a Trellis With Application to Multitarget Tracking

    Abstract 本文提出一种寻找K最优路径的方法. k最优路径的定义:1.the sum of the metrics of all k paths in the set is minimized. ...

  6. cmake编译安装mysql

    运维开发技术交流群欢迎大家加入一起学习(QQ:722381733) 前言:这里我使用的安装方式是(cmake编译),我选择的版本是:cmake-2.8.8.tar.gz.mysql-5.5.32.ta ...

  7. Centos 7 关闭firewall防火墙启用iptables防火墙

    一.关闭firewall防火墙 1.停止firewall systemctl stop firewalld.service 2.禁止firewall开机启动 systemctl disable fir ...

  8. CVE-2014-6271 漏洞告警

    原理:BASH除了可以将shell变量导出为环境变量,还可以将shell函数导出为环境变量!当前版本的bash通过以函数名作为环境变量名,以“(){”开头的字串作为环境变量的值来将函数定义导出为环境变 ...

  9. 51nod挑的部分5级题

    最近心情不好所以写代码来获得快落 4级题有点难做?然后就开始挑简单的5级题开始写 然后准备记录一些自己没有做出来 参考讨论区或者博客才做出来的题目 51nod_1189 阶乘分数 这个题参考了讨论区 ...

  10. CodeForces - 357D - Xenia and Hamming

    先上题目: D. Xenia and Hamming time limit per test 1 second memory limit per test 256 megabytes input st ...