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 ... 
随机推荐
- import downloadjs from 'downloadjs' 如果是自己写的函数 没用默认导出 记得加花括号 例如 import { download } from './data.js'
			import downloadjs from 'downloadjs' 如果是自己写的函数 没用默认导出 记得加花括号 例如 import { download } from './data.js' 
- Java以组的数量将字符串分组
			package org.jimmy.autosearch2019.test; import java.util.ArrayList; public class Test20190327 { publi ... 
- aaaaa
			svn://192.168.199.182/anti-counterfeiting/trunk svn://192.168.199.182/anti-ds/trunk/antifake-service ... 
- No-9.vi __终端中的编辑器
			vi —— 终端中的编辑器 01. vi 简介 1.1 学习 vi 的目的 在工作中,要对 服务器 上的文件进行 简单 的修改,可以使用 ssh 远程登录到服务器上,并且使用 vi 进行快速的编辑即可 ... 
- python-水仙花数
			>>> for a in range(1,10):... for b in range(0,10):... for c in range(0,10):... x=100*a+10*b ... 
- Swift 中的Range和NSRange不同
			Swift中的Ranges和Objective-C中的NSRange有很大的不同,我发现在处理Swift中Ranges相关的问题的时候,总是要花费比我想象的更多的时间.不过,现在回过头来看看,发现Sw ... 
- js实现音量拖拽的效果模拟
			<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>js ... 
- Intel CPU参数查询网站
			链接:https://ark.intel.com/#@Processors 
- Spring中RestTemplate的使用方法
			一.REST 在互联网中,我们会通过请求url来对网络上的资源做增删改查等动作,这里的请求包含两部分:动词,主要包括增.删.改.查:名词,就是网络中的各种资源.传统的非REST风格的请求方式是把动词和 ... 
- kvm安装图终端界面及形界面安装系统
			1.图形界面安装: qemu-img create -f qcow2 /kvm/os/vm-01.qcow2 16G mkdir -p /kvm/iso cd /kvm/iso 上传事先下载好的镜像文 ... 
