国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

CodeforcesRound#256(Div.2)題解

來源:懂視網(wǎng) 責編:小采 時間:2020-11-09 07:58:50
文檔

CodeforcesRound#256(Div.2)題解

CodeforcesRound#256(Div.2)題解:Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a n
推薦度:
導(dǎo)讀CodeforcesRound#256(Div.2)題解:Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a n

Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a n

Problem A:

A. Rewards

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Bizon the Champion is called the Champion for a reason.

Bizon the Champion has recently got a present — a new glass cupboard with n shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has a1 first prize cups, a2 second prize cups and a3third prize cups. Besides, he has b1 first prize medals, b2 second prize medals and b3 third prize medals.

Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:

  • any shelf cannot contain both cups and medals at the same time;
  • no shelf can contain more than five cups;
  • no shelf can have more than ten medals.
  • Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.

    Input

    The first line contains integers a1, a2 and a3 (0?≤?a1,?a2,?a3?≤?100). The second line contains integers b1, b2 and b3 (0?≤?b1,?b2,?b3?≤?100). The third line contains integer n (1?≤?n?≤?100).

    The numbers in the lines are separated by single spaces.

    Output

    Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).

    Sample test(s)

    input

    1 1 1
    1 1 1
    4
    

    output

    YES
    

    input

    1 1 3
    2 3 4
    2
    

    output

    YES
    

    input

    1 0 0
    1 0 0
    1
    

    output

    NO

    傳送門:點擊打開鏈接

    解題思路:

    求出放置所有獎杯和獎牌需要的最少架子的數(shù)目num,和n進行比較。

    代碼:

    #include 
    #include 
    
    int main()
    {
     int a1, a2, a3, b1, b2, b3, n;
     scanf("%d%d%d%d%d%d%d", &a1, &a2, &a3, &b1, &b2, &b3, &n);
     int num = ceil((a1 + a2 + a3) * 1.0 / 5) + ceil((b1 + b2 + b3) * 1.0 / 10);
     printf("%s\n", num <= n ? "YES" : "NO");
     return 0;
    }
    

    Problem B:

    B. Suffix Structures

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.

    At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.

    Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.

    Input

    The first line contains a non-empty word s. The second line contains a non-empty word t. Words s and t are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.

    Output

    In the single line print the answer to the problem. Print "need tree" (without the quotes) if word s cannot be transformed into word teven with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.

    It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.

    Sample test(s)

    input

    automaton
    tomat
    

    output

    automaton
    

    input

    array
    arary
    

    output

    array
    

    input

    both
    hot
    

    output

    both
    

    input

    need
    tree
    

    output

    need tree

    傳送門:點擊打開鏈接

    解題思路:

    如果串A中包含串B的所有字母,并且這些字母在串A和串B中排列順序相同,輸出“automaton”,否則,如果串A中包含串B的所有字母,我們在這種情況下在進行討論,如果A和B的長度相等,輸出“array”,如果A比B長,輸出“both”,否則輸出“need tree”。

    代碼:

    #include 
    #include 
    #include 
    using namespace std;
    
    const int MAXN = 105;
    int vis[MAXN];
    
    bool cmpa(string stra, string strb)
    {
     memset(vis, 0, sizeof(vis));
     int lena = stra.length();
     int lenb = strb.length();
     int k = 0;
     for(int i = 0; i < lenb; i++)
     {
     bool flag = true;
     for(int j = k; j < lena; j++)
     {
     if(!vis[j] && strb[i] == stra[j])
     {
     vis[j] = 1;
     k = j + 1;
     flag = false;
     break;
     }
     }
     if(flag) return false;
     }
     return true;
    }
    
    bool cmpb(string stra, string strb)
    {
     memset(vis, 0, sizeof(vis));
     int lena = stra.length();
     int lenb = strb.length();
     for(int i = 0; i < lenb; i++)
     {
     bool flag = true;
     for(int j = 0; j < lena; j++)
     {
     if(!vis[j] && strb[i] == stra[j])
     {
     vis[j] = 1;
     flag = false;
     break;
     }
     }
     if(flag) return false;
     }
     return true;
    }
    
    int main()
    {
     string stra, strb;
     cin >> stra >> strb;
     int lena = stra.length();
     int lenb = strb.length();
     if(cmpa(stra, strb))
     {
     cout << "automaton" << endl;
     }
     else if(cmpb(stra, strb))
     {
     if(lena == lenb)
     {
     cout << "array" << endl;
     }
     else if(lena > lenb)
     {
     cout << "both" << endl;
     }
     else
     {
     cout << "need tree" << endl;
     }
     }
     else
     {
     cout << "need tree" << endl;
     }
     return 0;
    }
    

    Problem C:

    C. Painting Fence

    time limit per test

    1 second

    memory limit per test

    512 megabytes

    input

    standard input

    output

    standard output

    Bizon the Champion isn't just attentive, he also is very hardworking.

    Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from one, the i-th plank has the width of 1 meter and the height of ai meters.

    Bizon the Champion bought a brush in the shop, the brush's width is 1 meter. He can make vertical and horizontal strokes with the brush. During a stroke the brush's full surface must touch the fence at all the time (see the samples for the better understanding). What minimum number of strokes should Bizon the Champion do to fully paint the fence? Note that you are allowed to paint the same area of the fence multiple times.

    Input

    The first line contains integer n (1?≤?n?≤?5000) — the number of fence planks. The second line contains n space-separated integersa1,?a2,?...,?an (1?≤?ai?≤?109).

    Output

    Print a single integer — the minimum number of strokes needed to paint the whole fence.

    Sample test(s)

    input

    5
    2 2 1 2 1
    

    output

    3
    

    input

    2
    2 2
    

    output

    2
    

    input

    1
    5
    

    output

    1

    傳送門:點擊打開鏈接

    解題思路:

    遞歸,貪心。粉刷籬笆,我們可以水平方向粉刷(只能刷到連續(xù)的部分),也可以豎直方向粉刷。按水平方向粉刷的話,刷的最少次數(shù)是min(a1,a2,a3,...,an-1);按豎直方向刷的話最少次數(shù)是這段連續(xù)籬笆的長度n。按上述方式刷完之后,必然會產(chǎn)生高度為0的籬笆(被全部刷過了),我們把這樣的籬笆作為分割點,分成左半部分,和右半部分,兩部分各是一段連續(xù)的籬笆,依次類推。

    一個錯誤的思路:每次刷的時候找所有籬笆高度的最大值h,和最長的連續(xù)籬笆的長度len,刷的時候取max(h,len),最多刷n次,算法復(fù)雜度O(n2)。這樣做的話,可能會使得籬笆變得分散,導(dǎo)致最終粉刷的次數(shù)變多。

    反例:

    3
    1 10 1

    錯誤的代碼:

     #include 
     #include 
     using namespace std;
    
     const int MAXN = 5010;
     int n, ans = 0, a[MAXN];
    
     int main()
     {
     scanf("%d", &n);
     for(int i = 0; i < n; i++)
     {
     scanf("%d", &a[i]);
     }
     while(true)
     {
     int maxv = *max_element(a, a + n);
     int maxh = -1, tmp = 0, first = 1;
     int s = 0, t = 0, ts = 0, tt = 0;
     for(int i = 0; i < n; i++)
     {
     if(a[i])
     {
     if(first)
     {
     ts = i;
     first = 0;
     }
     tt = i;
     tmp++;
     if(i == n - 1)
     {
     if(tmp > maxh)
     {
     maxh = tmp;
     s = ts;
     t = tt;
     }
     }
     }
     else
     {
     if(tmp > maxh)
     {
     maxh = tmp;
     s = ts;
     t = tt;
     }
     tmp = 0;
     first = 1;
     }
     }
     if(maxv > maxh)
     {
     *max_element(a, a + n) = 0;
     }
     else
     {
     for(int i = s; i <= t; i++)
     {
     a[i]--;
     }
     }
     ans++;
     if(0 == *max_element(a, a + n)) break;
     }
     printf("%d\n", ans);
     return 0;
     }


    代碼:

    #include 
    #include 
    using namespace std;
    
    const int MAXN = 5010;
    int n, a[MAXN];
    
    int solve(int l, int r)
    {
     if(l > r) return 0;
     int minh = *min_element(a + l, a + r + 1);
     int ret = r - l + 1, tot = minh;
     if(ret < minh)
     {
     for(int i = l; i <= r; i++)
     a[i] = 0;
     return ret;
     }
     else
     {
     for(int i = l; i <= r; i++)
     a[i] -= minh;
     int t = min_element(a + l, a + r + 1) - a;
     tot += solve(l, t - 1) + solve(t + 1, r);
     }
     return min(ret, tot);
    }
    
    int main()
    {
     scanf("%d", &n);
     for(int i = 0; i < n; i++)
     scanf("%d", &a[i]);
     printf("%d\n", solve(0, n - 1));
     return 0;
    }
    

    Problem D:

    D. Multiplication Table

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Bizon the Champion isn't just charming, he also is very smart.

    While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted ann?×?m multiplication table, where the element on the interdiv of the i-th row and j-th column equals i·j (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?

    Consider the given multiplication table. If you write out all n·m numbers from the table in the non-decreasing order, then the k-th number you write out is called the k-th largest number.

    Input

    The single line contains integers n, m and k (1?≤?n,?m?≤?5·105; 1?≤?k?≤?n·m).

    Output

    Print the k-th largest number in a n?×?m multiplication table.

    Sample test(s)

    input

    2 2 2
    

    output

    2
    

    input

    2 3 4
    

    output

    3
    

    input

    1 10 5
    

    output

    5

    傳送門:點擊打開鏈接

    解題思路:

    二分。需要求的是n*m乘法表中第k大的數(shù),我們可以對這個數(shù)ans進行二分查找,區(qū)間是[1, n * m],對于每一個可能的ans,我們求出比他小的數(shù)的個數(shù)sum += min((mid - 1) / i, m);(i = 1,2,3,..,n),記錄下小于k的最大的mid,即為我們所求的ans。

    代碼:

    #include 
    
    inline long long min(long long a, int b)
    {
     if(a < b) return a;
     return b;
    }
    
    int main()
    {
     int n, m;
     long long k, ans, l, r, sum, mid;
     scanf("%d%d%I64d", &n, &m, &k);
     l = 1, r = 1ll * n * m;//r = (long long)n * m;
     while(l <= r)
     {
     mid = (l + r) >> 1;
     sum = 0;
     for(int i = 1; i <= n; i++)
     sum += min((mid - 1) / i, m);
     if(sum < k)
     l = mid + 1, ans = mid;
     else
     r = mid - 1;
     }
     printf("%I64d\n", ans);
     return 0;
    }
    

    聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    CodeforcesRound#256(Div.2)題解

    CodeforcesRound#256(Div.2)題解:Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a n
    推薦度:
    標簽: 256 div round
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 亚洲欧美日韩国产 | 国产每日更新 | 国产成人91一区二区三区 | 蜜桃视频一区二区三区四区 | 亚欧激情| 91久久国产综合精品女同我 | 精品免费久久久久国产一区 | 国产夫妻精品 | 久久se精品一区二区国产 | 国产综合精品一区二区 | 欧美成人国产 | 日韩区| 色另类| 一区亚洲 | 国产欧美另类第一页 | 日韩欧美三级视频 | 国产欧美久久一区二区 | 国产一级片在线 | 91精品一区二区 | 国产又黄又爽的视频 | 欧美激情一区二区三区 | 国产一区二区三区免费 | 亚洲精品乱码久久久久久 | 日韩欧美亚洲综合 | 亚洲视频在线免费播放 | 国内一级一级毛片a免费 | 欧美人与禽zozzo性伦交 | 欧美专区第一页 | 日韩欧美精品综合一区二区三区 | 国产精品久久久久久永久牛牛 | 日本 黄 a| 欧美日韩在线精品一区二区三区 | 国产精品免费精品自在线观看 | 亚洲欧美啪啪 | 国产亚洲欧美在线人成aaaa | 99精品欧美一区二区三区综合在线 | 国产视频中文字幕 | 日韩欧美国产中文字幕 | 国产成人免费在线视频 | 免费毛片网 | 精品欧美一区二区三区免费观看 |