B3300 [USACO2011 Feb]Best Parenthesis 模拟
这是我今天遇到最奇怪的问题,希望有人帮我解释一下。。。
一开始我能得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 模拟的更多相关文章
- BZOJ3300: [USACO2011 Feb]Best Parenthesis 模拟
Description Recently, the cows have been competing with strings of balanced parentheses and compari ...
- BZOJ3300: [USACO2011 Feb]Best Parenthesis
3300: [USACO2011 Feb]Best Parenthesis Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 89 Solved: 42 ...
- 【BZOJ】3300: [USACO2011 Feb]Best Parenthesis(模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=3300 这个细节太多QAQ 只要将所有的括号'('匹配到下一个')'然后dfs即可 简单吧,,, #i ...
- [USACO2011 Feb]Best Parenthesis
Time Limit: 10 Sec Memory Limit: 128 MB Description Recently, the cows have been competing with stri ...
- 3301: [USACO2011 Feb] Cow Line
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 82 Solved: 49[Submit ...
- 【BZOJ】【3301】【USACO2011 Feb】Cow Line
康托展开 裸的康托展开&逆康托展开 康托展开就是一种特殊的hash,且是可逆的…… 康托展开计算的是有多少种排列的字典序比这个小,所以编号应该+1:逆运算同理(-1). 序列->序号:( ...
- BZOJ2274: [Usaco2011 Feb]Generic Cow Protests
2274: [Usaco2011 Feb]Generic Cow Protests Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 196 Solve ...
- BZOJ3301: [USACO2011 Feb] Cow Line
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 67 Solved: 39[Submit ...
- 2272: [Usaco2011 Feb]Cowlphabet 奶牛文字
2272: [Usaco2011 Feb]Cowlphabet 奶牛文字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 138 Solved: 97 ...
随机推荐
- css3背景渐变色代码
从上到下 #grad { background: -webkit-linear-gradient(red, blue); background: -o-linear-gradient(red, b ...
- CSS——新浪导航demo
主要运用的dispaly将a变成行内块,再用padding撑开宽度. <!DOCTYPE html> <html lang="en"> <head&g ...
- windows编译MaskRCNN
1.代码修改为3.0语言版本 2.setup_windows.py 文件内容为 #!/usr/bin/env python import numpy as np import os # on Wind ...
- mongodb分片集群安装教程
mongodb 集群包含副本集群,主从集群以及分片集群,分片集群比较复杂,这里测试我采用了三台机器,交差部署 blog地址:http://www.cnblogs.com/caoguo 一 .环境:#m ...
- ECharts实例开发学习笔记二——时间轴
记录一下ECharts时间轴的使用,首先是照着官方的示例做一遍,在这里不要忘了引入timelineOption.js,后面介绍如何动态创建时间轴的记录数,即根据需求可伸缩显示有多少天或者年月等轴标记数 ...
- C#斐波那契数列方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Python 之pytesseract模块读取知乎验证码案例
import pytesseract from PIL import Image import requests import time # 获取只会验证码图片并保存为本地 def get_data_ ...
- Python - 面对对象(基础)
目录 Python - 面对对象(基础) 一. 概述 二. 创建类和对象 三. 面向对象三大特征 封装 继承 多态 Python - 面对对象(基础) 一. 概述 面向过程:根据业务逻辑从上到下写垒代 ...
- BZOJ 1232 USACO 2008 Nov. 安慰奶牛Cheer
[题解] 对于每一条边,我们通过它需要花费的代价是边权的两倍加上这条边两个端点的点权. 我们把每条边的边权设为上述的值,然后跑一边最小生成树,再把答案加上最小的点权就好了. #include<c ...
- noip模拟赛 逃避
题目描述 给定一篇只含有大小写字母,空格以及 ′.′(不含引号)的长度为 L 的文章.文章被若干个 ′.′ 划分 成若干个句子,句子被若干个空格划分成单词.你需要将文章中每个句子第一个单词的首字母改成 ...