topcoder srm 553
div1 250pt:
题意:。。。
解法:先假设空出来的位置是0,然后模拟一次看看是不是满足,如果不行的话,我们只需要关心最后栈顶的元素取值是不是受空白处的影响,于是还是模拟一下。
// BEGIN CUT HERE // END CUT HERE
#line 5 "Suminator.cpp"
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cassert>
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = ;
ll stk[N];
class Suminator
{
public:
int findMissing(vector <int> program, int wantedResult){
//$CARETPOSITION$
int top=;
int n=program.size();
for(int i=;i<n;i++){
if(program[i] == || program[i] == -){
if(top >= ){
ll res = stk[top]+stk[top-];
stk[--top]=res;
// if(res > wantedResult)return -1;
}else if(top == ){
stk[++top] = ;
}
}else{
stk[++top] = program[i];
}
}
if(stk[top] == wantedResult)return ;
bool have[N];memset(have,,sizeof(have));
top = ;
for(int i=;i<n;i++){
if(program[i] == ){
if(top >= ){
ll res = stk[top] + stk[top-];
bool ok = have[top] || have[top-];
stk[--top] = res;
// if(res > wantedResult)return -1;
have[top] = ok;
}else if(top == ){
stk[++top] = ;
have[top] = ;
}
}else if(program[i] == -){
stk[++top] = ;
have[top] = ;
}else{
stk[++top] = program[i];
have[top] = ;
}
}
if(have[top] == )return -;
else if(stk[top] >= wantedResult)return -;
else return wantedResult - stk[top]; } // BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); if ((Case == -) || (Case == )) test_case_3(); if ((Case == -) || (Case == )) test_case_4(); if ((Case == -) || (Case == )) test_case_5(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { int Arr0[] = {,-,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = ; verify_case(, Arg2, findMissing(Arg0, Arg1)); }
void test_case_1() { int Arr0[] = {, , , , , -}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = ; verify_case(, Arg2, findMissing(Arg0, Arg1)); }
void test_case_2() { int Arr0[] = {-, , , , , , , }; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = ; verify_case(, Arg2, findMissing(Arg0, Arg1)); }
void test_case_3() { int Arr0[] = {-, , , , , , , }; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = -; verify_case(, Arg2, findMissing(Arg0, Arg1)); }
void test_case_4() { int Arr0[] = {, , , , -, , , , }; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = -; verify_case(, Arg2, findMissing(Arg0, Arg1)); }
void test_case_5() { int Arr0[] = {, -, , }; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = -; verify_case(, Arg2, findMissing(Arg0, Arg1)); } // END CUT HERE };
// BEGIN CUT HERE
int main(){
Suminator ___test;
___test.run_test(-);
return ;
}
// END CUT HERE
250pt
div1 500pt
有点复杂的dp,有待实现
topcoder srm 553的更多相关文章
- TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E
传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- TopCoder SRM 667 Div.2题解
概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...
- Topcoder Srm 673 Div2 1000 BearPermutations2
\(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...
- Topcoder Srm 671 Div2 1000 BearDestroysDiv2
\(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...
- [topcoder]SRM 646 DIV 2
第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...
- [topcoder]SRM 633 DIV 2
第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...
- TopCoder<SRM>上的一道1100分的题目解析附代码
首先我们来简单看一下这道题的statement Problem Statement Note that in the following problem statement, all quo ...
随机推荐
- 在Vue中遇到的各种坑 及性能提升
Vue: (1) 没有再模板里引用data数据,会不会引起update.beforeUpdate生命周期函数的执行? 不会 (2)组件改成异步 (3)v-once (4)如果不用template ...
- spring注解开发-容器创建全过程(源码)
1.Spring容器的创建会经历refresh()方法[创建刷新](以AnnotationConfigApplicationContext为例) public AnnotationConfigAppl ...
- cf上分的失落->高兴->更失落
cf昨日做出一个题居然div2打了1800多名直接上分了...我原以为垂直落地但是....我现在1399差一分就能蓝名了啊啊啊啊,以后不一定会有这个水平的啊,给个蓝名体验卡不行吗,多加一分会死啊... ...
- python基础知识07-函数作用域和匿名函数
1.匿名函数 list(filter(lamda a:a>3,[1,2,3,4,5])) 一般和过滤器一起使用 2.函数的作用域 a = 123 def test(): a = 666 a = ...
- [jzoj5073 GDOI2017第二轮模拟] 影魔
Description 影魔,奈文摩尔,据说有着一个诗人的灵魂.事实上,他吞噬的诗人灵魂早已成千上万.千百年来,他收集了各式各样的灵魂,包括诗人.牧师.帝王.乞丐.奴隶.罪人,当然,还有英雄.每一个灵 ...
- HDU 5076 Memory
Memory Time Limit: 4000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 50 ...
- FZU- Problem 1147 Tiling,递推坑题,大数水过~~
Problem 1147 Tiling Time Limit: 1000 mSec Memory Limit : 32768 KB http://acm.fzu.edu.cn/problem.php? ...
- FZU-2148-Moon Game,,几何计算~~
Problem 2148 Moon Game Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description Fat brothe ...
- bzoj 1251序列终结者 splay 区间翻转,最值,区间更新
序列终结者 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 4594 Solved: 1939[Submit][Status][Discuss] De ...
- Genymotion 常见问题Unable to configure the network adapter for the virtual device解决
Genymotion 常见问题Unable to configure the network adapter for the virtual device解决 参考:http://www.pczhis ...