生活随笔
收集整理的這篇文章主要介紹了
SRM 533 DIV2
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
很長時間沒做TC了,再說自己做的也確實相當(dāng)少,所以不是很熟+思路來的比較慢所以做得不是多么好,只做出了250pt,500pt的思路對還沒敲完就結(jié)束了。話說TC,CF什么的真的很鍛煉人的思維能力可就是老在晚上舉行,所以弄得....
250pt就是求一個
x + z = d;
2*x + 4*y + 4*z = f;
y ?+ z = t;推出公式計算即可:
500pt
題意:
給定你一個序列,里面含有一個-1其余都是非負(fù)數(shù)另開一個棧,按如下操作進(jìn)行:
遇到大于0的進(jìn)棧,遇到0取棧頂兩個元素相加再放進(jìn)棧,最后得到棧頂?shù)脑貫閣antresult.
給出序列和wantresult,問-1這個位置如果是0就輸出0,如果是非負(fù)數(shù)就輸出非負(fù)數(shù),否則輸出-1
思路:
模擬,就是先將-1當(dāng)做0處理看是否能夠得到wantresult,如果不能再將-1當(dāng)做1處理,我在這里直接就看了最后得到的棧頂元素是否等于wantresult,結(jié)果跑系統(tǒng)數(shù)據(jù)時錯了,原因是可能-1這個位置本身去什么(除去0)都不會對棧頂元素造成影響,所以再把-1當(dāng)做2放進(jìn)去,檢查一下兩種情況下棧頂元素是否相同,若相同則輸出-0;否則通過1得到的結(jié)果處理輸出非負(fù)數(shù)。
View Code #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <
set>
#include <map>
#include <
string>
#define CL(a,num) memset((a),(num),sizeof(a))
#define iabs(x) ((x) > 0 ? (x) : -(x))
#define Min(a,b) (a) > (b)? (b):(a)
#define Max(a,b) (a) > (b)? (a):(b)
#define maxn 50004
#define N 207
#define M 507
#define ll long long
#define inf 0x7f7f7f7f
#define MOD 100000007
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;stack<ll>
st1,st2,st3;
class Suminator
{public:int findMissing(vector <
int> program,
int wantedResult){vector<ll>p;
int i;int sz =
program.size();int idx =
0;for (
int i =
0; i < sz; ++
i){if (program[i] == -
1) idx =
i;p.push_back(program[i]);}for (i =
0; i <
200; ++
i){st1.push(0); st2.push(
0); st3.push(
0);}p[idx] =
0;for (i =
0; i < sz; ++
i){if (p[i] ==
0){ll a =
st1.top(); st1.pop();ll b =
st1.top(); st1.pop();st1.push(a +
b);}else st1.push(p[i]);}if (st1.top() == (ll)wantedResult)
return 0;p[idx] =
1;for (i =
0; i < sz; ++
i){if (p[i] ==
0){ll a =
st2.top(); st2.pop();ll b =
st2.top(); st2.pop();st2.push(a +
b);}else st2.push(p[i]);}p[idx] =
2;for (i =
0; i < sz; ++
i){if (p[i] ==
0){ll a =
st3.top(); st3.pop();ll b =
st3.top(); st3.pop();st3.push(a +
b);}else st3.push(p[i]);}if (st2.top() == st3.top())
return -
1;ll ans = (ll)wantedResult - st2.top() +
1ll;if (ans >= 1ll)
return (
int)(ans);else return -
1;}
}; 1000pt沒看。。
轉(zhuǎn)載于:https://www.cnblogs.com/E-star/archive/2012/08/25/2656899.html
總結(jié)
以上是生活随笔為你收集整理的SRM 533 DIV2的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。