欧美1区2区3区激情无套,两个女人互添下身视频在线观看,久久av无码精品人妻系列,久久精品噜噜噜成人,末发育娇小性色xxxx

Codeforces edu76- D. Yet Another Monster Killing Problem

比賽的時(shí)候想著貪心寫,一直WA。賽后補(bǔ)題補(bǔ)了兩天,總算是有點(diǎn)頭緒了

Link: Yet Another Monster Killing Problem

D -Yet Another Monster Killing Problem

Description:

You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power ai. Each hero is characterized by his power pi and endurance si.

The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.

When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k+1). When the hero fights the monster, there are two possible outcomes:

if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than si monsters during each day), or if all monsters are defeated — otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.

Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.

Input
The first line contains one integer t (1≤t≤1e5) — the number of test cases. Then the test cases follow.

The first line of each test case contains one integer n (1≤n≤2?1e5) — the number of monsters in the dungeon.

The second line contains n integers a1, a2, ..., an (1≤ai≤1e9), where ai is the power of the i-th monster.

The third line contains one integer m (1≤m≤2?1e5) — the number of heroes in your party.

Then m lines follow, each describing a hero. Each line contains two integers pi and si (1≤pi≤1e9, 1≤si≤n) — the power and the endurance of the i-th hero.

It is guaranteed that the sum of n+m over all test cases does not exceed 2?1e5.

Output
For each test case print one integer — the minimum number of days you have to spend to defeat all of the monsters (or ?1 if it is impossible).

Example
input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
output
5
-1

Problem solving:
這道題的意思就是給你一堆怪物,然后給你幾個(gè)戰(zhàn)士。怪物和戰(zhàn)士都有自己的攻擊力,戰(zhàn)士還會(huì)有一個(gè)耐力。只要戰(zhàn)士的攻擊力不小于怪物的攻擊力,就可以把這個(gè)怪物殺死。每天只能派出一個(gè)戰(zhàn)士,并且戰(zhàn)士每殺一只怪物耐力減一。每個(gè)戰(zhàn)士一天可以盡量多的殺怪物。問你最少需要幾天可以把怪物殺完,如果殺不完就輸出-1.注意:殺死怪物的順序應(yīng)該與輸入的順序一樣,不能變

這里我補(bǔ)的代碼里面主要思想是貪心。一共有n個(gè)怪物。那就把堅(jiān)持i(1<=i<=n)天的戰(zhàn)士的最大的攻擊力存起來。然后從第一個(gè)怪物開始遍歷,找到最多可以一天內(nèi)殺死的怪物數(shù),再從下一個(gè)怪物開始找,循環(huán)下去直到找完或者輸出-1。具體可以看代碼注釋,個(gè)人認(rèn)為寫的還是很明白的。

Code:

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie();
    int N, n, m;
    cin >> N;
    while (N--)
    {
        int         flag = 0, ans = 0;
        cin >> n;
        vector<int> a(n);
        vector<int> mx(n); //mx數(shù)組的含義很重要,它代表的是耐力為i的戰(zhàn)士的最大攻擊力
        for (int i = 0; i < n; i++)
            cin >> a[i];
        cin >> m;
        for (int i = 0, x, y; i < m; i++)
        {
            cin >> x >> y;
             mx[y - 1] = max(mx[y - 1], x);//這里我們下標(biāo)從0開始。mx[i]代表的是可以堅(jiān)持i天的戰(zhàn)士的最大攻擊力
        }
        for (int i = n - 2; i >= 0; i--)
            mx[i] = max(mx[i], mx[i + 1]);//這樣處理是為了得到可以堅(jiān)持至少i天的戰(zhàn)士的最大攻擊力,因?yàn)槿绻硞€(gè)戰(zhàn)士耐力大于i并且攻擊力也更大,那么mx[i]的值就應(yīng)該是他的攻擊力。所以我們要從后往前推儲(chǔ)存最大值
        for (int i = 0; i < n;)//從頭開始?xì)⒐治?        {
            int j = i, x = 0;
            while (j < n && mx[j - i ] >= max(x, a[j]))//這里mx的下標(biāo)是j-i,要好好理解。這個(gè)while循環(huán)其實(shí)就是在找從第一只怪物開始嗎,一天內(nèi)最多殺死幾只怪物
            {
                x = max(x, a[j]);
                j++;
            }//分別看當(dāng)前一天內(nèi)最多可以殺幾只怪物,max(x,a[j])代表的就是這幾天內(nèi)怪物的最大攻擊力,mx[j-i]代表的是戰(zhàn)士的最大攻擊力,如果戰(zhàn)士的最大攻擊力已經(jīng)小于怪物了,說明連著打只能打j-i只怪物。然后跳出這個(gè)while循環(huán)
            if (j == i)
            {
                flag = 1; break;
            }//這是處理一下,j==i的情況只有一種情況會(huì)出現(xiàn),即最大的戰(zhàn)士攻擊力小于這個(gè)怪物的攻擊力,那么肯定殺不完
            ans++;//殺死這j-i只怪物用一天
            i = j;//從上一天殺死的最后一只怪物的下一只怪物開始下一次循環(huán)
        }
        if (flag)
            cout << "-1\n";
        else
            cout << ans << endl;
    }
}
全部評(píng)論

相關(guān)推薦

你出生在農(nóng)村,與其它農(nóng)村小孩子無異小學(xué)時(shí)你對(duì)成績沒有概念,只感覺上課不聽課也是無聊,只知道不寫完作業(yè)會(huì)被老師罰站一到考試,自己成績總是名列靠前,即使偶爾落后,你也從不在意中學(xué)時(shí)你覺得課本的東西很簡單,隨便學(xué)學(xué)就會(huì)了,并沒有大量刷題你總是想不通,那些所謂的數(shù)學(xué)物理中難題,明明是在送分,為什么你的同學(xué)總是想不出解題方法高中時(shí)這三年你過的不容易,晚睡早起,給了自己很多壓力.但是你也發(fā)現(xiàn)自己是有些小聰明的,你感覺班里有些同學(xué)很刻苦,但成績比你差遠(yuǎn)了。那些數(shù)學(xué)題和物理題的陷阱,同學(xué)一遍遍踩坑,但是你總能發(fā)現(xiàn)并避開它們.“為了父母的期盼,為了恩師的厚望,為了天賜的智慧,為了青春的理想......”“天行健...
創(chuàng)作助手_劉北:其實(shí),這種已經(jīng)是神童級(jí)別的了,不費(fèi)吹灰之力就能拿到自己想要的東西,就像機(jī)器按照程序走了一遍,就像我小時(shí)候看愛情公寓,覺得他們都很慘,幾個(gè)人只能擠在一個(gè)房間里合租,但是好在他們有一群非常好的朋友,隨著時(shí)間的推移,慢慢長大了,在看愛情公寓的時(shí)候,覺得他們都很厲害,博士、留學(xué)生、***、電臺(tái)公子,數(shù)學(xué)天才,任何一個(gè)都是我可望而不可即的,更別說可以在異地認(rèn)識(shí)一群更好的朋友了,所以呢,人還是要自給自足,滿足當(dāng)下,不要攀比,意氣風(fēng)發(fā)的且有理想的18歲少年永遠(yuǎn)都存在,只不過隨著時(shí)間的推移他被你包裹在了洋蔥的最深處。
點(diǎn)贊 評(píng)論 收藏
分享
有禮貌的山羊追趕太陽:太典了,連筆試都沒有開始就因?yàn)镠C滿了而結(jié)束了,而且還卡你不讓你再投其他部門的。
點(diǎn)贊 評(píng)論 收藏
分享
不愿透露姓名的神秘牛友
03-28 13:48
hory權(quán):校招vip純神人了,還說自己是什么師范大學(xué)的
點(diǎn)贊 評(píng)論 收藏
分享
MGlory:我當(dāng)初有一個(gè)老師告訴我簡歷要寫的簡單,最好只一面,項(xiàng)目可以寫核心的,進(jìn)面了自然會(huì)問你的
點(diǎn)贊 評(píng)論 收藏
分享
評(píng)論
2
1
分享

創(chuàng)作者周榜

更多
??途W(wǎng)
??推髽I(yè)服務(wù)