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 ...
随机推荐
- uva 1451 数形结合
思路:枚举点t,寻找满足条件的点t': 计sum[i]为前i项合,平均值即为sum[t]-sum[t'-1]/t-t'+1 设(Pi=(i,Si),表示点在s中的位置,那么就可以画出坐标图,问题就转化 ...
- android 解密工具
androguard. 这个是python写的 安装: pip install androguard
- SpringBoot自定义一个starter
@Configuration //指定这个类是一个配置类 @ConditionalOnXXX //在指定条件成立的情况下自动配置类生效 @AutoConfigureAfter //指定自动配置类的顺序 ...
- html自动刷新
头部<meta http-equiv="refresh" content="10"> 或者js实现 <script language=&quo ...
- UVa-133-救济金发放
这题的话,我们首先对于移动函数可以知道,因为只是顺逆的关系,也就是加一或者减一,所以我们每次移动的时候,都补上一个小于n的最大整数,然后取模,这样就不会有负数,而且加之后的结果不会超过2*n,所以我们 ...
- IO之Object流举例
import java.io.*; public class TestObjectIO { public static void main(String args[]) throws Exceptio ...
- mysql5.7配置
my3306.cnf [client] port = 3306 #端口socket = /data/mysql3306/mysql3306.sock #mysql以socket方式运行的soc ...
- (3) openssl genrsa(生成rsa私钥)
genrsa用于生成RSA私钥,不会生成公钥,因为公钥提取自私钥,如果需要查看公钥或生成公钥,可以使用openssl rsa命令. 使用man genrsa查询其用法. openssl genrsa ...
- 对于easyui $.messager.alert和 $.messager.confirm 不同浏览器中位置控制
$.messager.confirm({ title: '种子购买', msg: '确定购买这个'+seedName+'的种子嘛?', top:, fn: function (r) { if (r){ ...
- 杭电 2120 Ice_cream's world I (并查集求环数)
Description ice_cream's world is a rich country, it has many fertile lands. Today, the queen of ice_ ...