日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁(yè) > php框架 > codeigniter > Codeforces Round #269 (Div. 2) Solution

Codeforces Round #269 (Div. 2) Solution

來(lái)源:程序員人生   發(fā)布時(shí)間:2014-09-30 07:29:17 閱讀次數(shù):3819次

又趁夜擼了一發(fā)DIV2,然后由于困完掛了。

現(xiàn)在最終測(cè)試的結(jié)果還沒(méi)有出來(lái),估計(jì)寫(xiě)完就出來(lái)了。

通過(guò)了前四道題的Pretest.

update:這一次rank220,坑了!


A:給你六個(gè)長(zhǎng)度(分別是四肢,頭,軀干),讓你判斷這是什么物種。判斷規(guī)則十分清楚了,然而我自己沒(méi)注意看。。。導(dǎo)致被hack,并wa了數(shù)次。

思路:排序后直接找出四個(gè)相同的長(zhǎng)度,若不存在為alien,否則剩下的兩個(gè)相等elephant,再否則bear.

Code:

#include <cstdio> #include <cstring> #include <climits> #include <algorithm> using namespace std; int main() { int a[6]; register int i, j; for(i = 0; i < 6; ++i) scanf("%d", &a[i]); sort(a, a + 6); int ins = -1; for(i = 0; i <= 2; ++i) if (a[i] == a[i + 1] && a[i + 1] == a[i + 2] && a[i + 2] == a[i + 3]) { ins = i; break; } if (ins == -1) { puts("Alien"); return 0; } int tmp1, tmp2; if (ins == 0) tmp1 = a[4], tmp2 = a[5]; if (ins == 1) tmp1 = a[0], tmp2 = a[5]; if (ins == 2) tmp1 = a[0], tmp2 = a[1]; if (tmp1 == tmp2) puts("Elephant"); else puts("Bear"); return 0; }

B:有n項(xiàng)工作,每個(gè)工作都有一個(gè)difficulty,要求以difficulty不下降的順序完成這些工作。若存在至少三種方案,輸出其中的三種,否則輸出no.

思路:首先排序后找出若干塊連續(xù)的相同塊,那么他們長(zhǎng)度的階乘積就是總的方案數(shù),首先判斷是否不超過(guò)3.

若存在3種方案,我們這樣構(gòu)造方案。

(1)直接就是排序后的標(biāo)號(hào)序列

(2)在(1)基礎(chǔ)上,找出第一個(gè)長(zhǎng)度不為1的塊交換前兩個(gè)元素

(3)在(1)基礎(chǔ)上,找出最后個(gè)長(zhǎng)度不為1的塊交換最后兩個(gè)元素

不難證明這樣做是正確的。

Code:

#include <cstdio> #include <cstring> #include <cctype> #include <iostream> #include <algorithm> using namespace std; #define N 2010 struct Node { int lab, dif; Node(int _lab = 0, int _dif = 0):lab(_lab),dif(_dif){} bool operator < (const Node &B) const { return dif < B.dif; } }S[N], S1[N], S2[N]; int begin[N], end[N], size[N], tot; int main() { int n; scanf("%d", &n); register int i, j, k; int x; for(i = 1; i <= n; ++i) { scanf("%d", &x); S[i] = Node(i, x); } sort(S + 1, S + n + 1); S[n + 1].dif = -1 << 30; unsigned long long res = 1; bool find = 0; for(i = 1; i <= n;) { for(j = i; S[j].dif == S[j + 1].dif; ++j); size[++tot] = j - i + 1; begin[tot] = i; end[tot] = j; for(k = 2; k <= j - i + 1; ++k) { res *= k; if (res >= 3) find = 1; } i = j + 1; } if (!find) { printf("NO"); return 0; } puts("YES"); for(i = 1; i < n; ++i) printf("%d ", S[i].lab); printf("%d ", S[n].lab); memcpy(S1, S, sizeof(S)); for(i = 1; i <= tot; ++i) if (size[i] >= 2) { swap(S1[begin[i]], S1[begin[i] + 1]); break; } for(i = 1; i < n; ++i) printf("%d ", S1[i].lab); printf("%d ", S1[n].lab); memcpy(S2, S, sizeof(S)); for(i = tot; i >= 1; --i) if (size[i] >= 2) { swap(S2[end[i]], S2[end[i] - 1]); break; } for(i = 1; i < n; ++i) printf("%d ", S2[i].lab); printf("%d ", S2[n].lab); return 0; }

C:用指定張數(shù)的撲克牌搭建建筑,問(wèn)可以搭建成多少種不同的層數(shù)。詳細(xì)題意看原題。

顯然若某一層有t個(gè)房間,那么這一層消耗的牌數(shù)為3*t-1

那么若一共s層,第i層房間數(shù)為ai,則總牌數(shù)為3*(a1+a2+...+as)-s

也就是說(shuō),我們首先判斷(n+s)%3=0,則s符合條件。但是還要保證房間數(shù)遞增,即a1>=1,ai>ai-1(2<=i<=s),于是a1+a2+...+as>=(1+s)*s/2

我們知道當(dāng)(n+s)/3>=(1+s)*s/2時(shí),我們總能構(gòu)造出一組ai,使得其滿足條件。反之則一定不能。

顯然s在sqrt(n)范圍內(nèi),因此枚舉到10^6就可以了。

Code:

#include <cstdio> #include <cstring> #include <climits> #include <algorithm> #include <iostream> #include <cmath> using namespace std; typedef long long LL; int main() { LL n; scanf("%I64d", &n); int res = 0; register int i, j; for(i = 1; i <= 1000000 && i <= n; ++i) { if ((n + i) % 3 == 0) { LL last = (n + i) / 3; if (last >= (LL)i * (i + 1) / 2) ++res; } } printf("%d", res); return 0; }

D:自己腦補(bǔ)= =

思路:差分后裸kmp串匹配,注意細(xì)節(jié)。

Code:

#include <cstdio> #include <cstring> #include <cctype> #include <iostream> #include <algorithm> using namespace std; #define N 200010 int a1[N], a2[N], res[N], text[N], pre[N], dp[N]; bool end[N]; int main() { int n, w; scanf("%d%d", &n, &w); if (w == 1) { printf("%d", n); return 0; } if (n < w) { printf("0"); return 0; } register int i, j; for(i = 1; i <= n; ++i) scanf("%d", &a1[i]); for(i = 1; i <= w; ++i) scanf("%d", &a2[i]); for(i = 1; i < w; ++i) res[i] = a2[i + 1] - a2[i]; --w; for(i = 1; i < n; ++i) text[i] = a1[i + 1] - a1[i]; --n; pre[1] = 0; j = 0; res[w + 1] = (int)1e9; for(i = 2; i <= w; ++i) { while(j && res[j + 1] != res[i]) j = pre[j]; if (res[j + 1] == res[i]) ++j; pre[i] = j; } int tot = 0; j = 0; for(i = 1; i <= n; ++i) { while(j && res[j + 1] != text[i]) j = pre[j]; if (res[j + 1] == text[i]) ++j; if (j == w) ++tot; } printf("%d ", tot); return 0; }

生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 在线看av网址| 午夜精品久久久久久久久久久久久 | 亚洲欧美中文日韩在线v日本 | 久久小视频 | 日韩不卡 | 精品国产区 | a级毛片免费全部播放 | 日韩三级免费观看 | 热久久综合网 | 日韩免费在线视频 | 免费国产一区二区 | 中文字幕av免费 | 综合色婷婷一区二区亚洲欧美国产 | 国产福利视频在线 | 日韩精品三区 | 久久国产精品成人免费观看的软件 | 日韩午夜激情 | 伊人天堂网 | 极品久久| 久久精品不卡 | 亚洲欧美一区二区三区国产精品 | 亚洲三级在线播放 | 麻豆视频91 | 亚洲精品在线观看免费 | 国产在视频线在精品视频55 | 成年人免费看 | 九九视频一区 | 国产一区二区h | 国产精品久久久久免费 | 久久久午夜视频 | 国产成人综合在线 | 久久久免费毛片 | 麻豆久久久久久 | 欧美 亚洲 另类 激情 另类 | 黄色毛片在线视频 | www五月天| 国产一区二区三区在线看 | 男人天堂国产 | 中文字幕+乱码+中文字 | 亚洲欧美视频一区 | 国产一区二区高清 |