• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答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
    當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

    CodeforcesRound#297(Div.2)(ABCDE題解)

    來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-09 15:37:18
    文檔

    CodeforcesRound#297(Div.2)(ABCDE題解)

    CodeforcesRound#297(Div.2)(ABCDE題解):比賽鏈接:http://codeforces.com/contest/525 算是比較簡單的一場了,拖了好久現(xiàn)在才補(bǔ) A. Vitaliy and Pie time limit per test:2 seconds memory limit per test:256 megabytes After a hard day Vitaly
    推薦度:
    導(dǎo)讀CodeforcesRound#297(Div.2)(ABCDE題解):比賽鏈接:http://codeforces.com/contest/525 算是比較簡單的一場了,拖了好久現(xiàn)在才補(bǔ) A. Vitaliy and Pie time limit per test:2 seconds memory limit per test:256 megabytes After a hard day Vitaly

    比賽鏈接:http://codeforces.com/contest/525 算是比較簡單的一場了,拖了好久現(xiàn)在才補(bǔ) A. Vitaliy and Pie time limit per test:2 seconds memory limit per test:256 megabytes After a hard day Vitaly got very hungry and he wants to eat his favor

    比賽鏈接:http://codeforces.com/contest/525

    算是比較簡單的一場了,拖了好久現(xiàn)在才補(bǔ)


    A. Vitaliy and Pie

    time limit per test:2 seconds

    memory limit per test:256 megabytes


    After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n?-?1)-th room to the n-th room. Thus, you can go to room x only from room x?-?1.

    The potato pie is located in the n-th room and Vitaly needs to go there.

    Each pair of consecutive rooms has a door between them. In order to go to room x from room x?-?1, you need to open the door between the rooms with the corresponding key.

    In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.

    Each of the first n?-?1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.

    Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.

    Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number.

    Input

    The first line of the input contains a positive integer n (2?≤?n?≤?105) — the number of rooms in the house.

    The second line of the input contains string s of length 2·n?-?2. Let's number the elements of the string from left to right, starting from one.

    The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i?+?1)?/?2.

    The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i?/?2 to room i?/?2?+?1.

    Output

    Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n.

    Sample test(s)

    Input

    3
    aAbB
    

    Output

    0
    

    Input

    4
    aBaCaB
    

    Output

    3
    

    Input

    5
    xYyXzZaZ
    

    Output

    2
    


    題目大意:有n-1個門大寫字母表示,n-1把鑰匙小寫字母表示,大小寫相對應(yīng)的鑰匙能開相對應(yīng)的門,每次遇到一個鑰匙可以將它收起來或者直接使用,用過一次就沒了,問最少還要買多少鑰匙才能通過所有的門


    題目分析:hash存一下,簡單模擬


    #include 
    #include 
    int const MAX = 1e6;
    
    char s[MAX];
    int hash[60];
    
    int main()
    {
     int n, ans = 0;
     scanf("%d %s", &n, s);
     int len = strlen(s);
     memset(hash, 0, sizeof(hash));
     for(int i = 0; i < len; i++)
     {
     if(s[i] >= 'a' && s[i] <= 'z')
     hash[s[i] - 'a'] ++;
     else 
     {
     if(hash[s[i] - 'A'])
     hash[s[i] - 'A'] --;
     else
     ans ++;
     }
     }
     printf("%d\n", ans);
    }




    B. Pasha and String

    time limit per test:2 seconds

    memory limit per test:256 megabytes


    Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string.

    Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent m days performing the following transformations on his string — each day he chose integer ai and reversed a piece of string (a segment) from position ai to position |s|?-?ai?+?1. It is guaranteed that 2·ai?≤?|s|.

    You face the following task: determine what Pasha's string will look like after m days.

    Input

    The first line of the input contains Pasha's string s of length from 2 to 2·105 characters, consisting of lowercase Latin letters.

    The second line contains a single integer m (1?≤?m?≤?105) — the number of days when Pasha changed his string.

    The third line contains m space-separated elements ai (1?≤?ai; 2·ai?≤?|s|) — the position from which Pasha started transforming the string on the i-th day.

    Output

    In the first line of the output print what Pasha's string s will look like after m days.

    Sample test(s)

    Input

    abcdef
    1
    2
    

    Output

    aedcbf
    

    Input

    vwxyz
    2
    2 2
    

    Output

    vwxyz
    

    Input

    abcdef
    3
    1 2 3
    

    Output

    fbdcea
    


    題目大意:給1個字符串長度為len,要操作m次,每次將第a[i]到第len-a[i]+1這段子串逆置,問最終字符串成什么樣


    題目分析:用reverse函數(shù)肯定T,同一個數(shù)操作偶數(shù)次相當(dāng)于沒動,所以算出要變換奇數(shù)次個數(shù)的數(shù),交換即可


    #include 
    #include 
    #include 
    using namespace std;
    char s[200005];
    int a[100005];
    
    int main()
    {
     scanf("%s", s + 1);
     int len = strlen(s + 1), m, get;
     scanf("%d", &m);
     while(m--)
     { 
     scanf("%d", &get);
     a[get] ++; 
     }
     for(int i = 1; i <= len / 2; i++)
     a[i] += a[i - 1];
     for(int i = 1; i <= len / 2; i++)
     if(a[i] % 2)
     swap(s[i], s[len + 1 - i]);
     printf("%s\n", s + 1);
    }
    



    C. Ilya and Sticks

    time limit per test:2 seconds

    memory limit per test:256 megabytes


    In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li.

    Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of sticks remain unused. Bending sticks is not allowed.

    Sticks with lengths a1, a2, a3 and a4 can make a rectangle if the following properties are observed:

  • a1?≤?a2?≤?a3?≤?a4
  • a1?=?a2
  • a3?=?a4
  • A rectangle can be made of sticks with lengths of, for example, 3 3 3 3 or 2 2 4 4. A rectangle cannot be made of, for example, sticks 5 5 5 7.

    Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length 5 can either stay at this length or be transformed into a stick of length 4.

    You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks?

    Input

    The first line of the input contains a positive integer n (1?≤?n?≤?105) — the number of the available sticks.

    The second line of the input contains n positive integers li (2?≤?li?≤?106) — the lengths of the sticks.

    Output

    The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.

    Sample test(s)

    Input

    4
    2 4 4 2
    

    Output

    8
    

    Input

    4
    2 2 3 5
    

    Output

    0
    

    Input

    4
    100003 100004 100005 100006
    

    Output

    10000800015
    


    題目大意:給n個木條,求從中選擇4個出來組成長方形,能組成長方形的四個邊滿足a1<=a2<=a3<=a4,a1=a2,a3=a4,且每根木條的長度可以減1使用,求所能組成的長方形的最大面積


    題目分析:從大到小排序,從大的開始選,選的時候注意減1的情況,開始看錯題了,以為只拼一個,其實(shí)是可以拼多個


    #include 
    #include 
    #include 
    #define ll long long
    using namespace std;
    int const MAX = 1e5;
    ll l[MAX];
    
    bool cmp(ll a, ll b)
    {
     return a > b;
    }
    
    int main()
    {
     int n;
     scanf("%d", &n);
     if(n < 4)
     {
     printf("0\n");
     return 0;
     }
     for(int i = 0; i < n; i++)
     scanf("%lld", &l[i]);
     sort(l, l + n, cmp);
     ll a = 0, b = 0, ans = 0;
     for(int i = 0; i < n - 1; i++)
     {
     if(!a && (l[i] == l[i + 1]))
     {
     a = l[i];
     i ++;
     continue;
     }
     else if(!a && (l[i] == l[i + 1] + 1))
     {
     a = l[i + 1];
     i ++;
     continue;
     }
     if(l[i] == l[i + 1])
     {
     b = l[i];
     ans += a * b;
     a = 0;
     b = 0;
     i ++;
     }
     else if(l[i] == l[i + 1] + 1)
     {
     b = l[i + 1];
     ans += a * b;
     a = 0;
     b = 0;
     i ++;
     }
     }
     printf("%lld\n", ans);
    }



    D. Arthur and Walls

    time limit per test:2 seconds

    memory limit per test:512 megabytes


    Finally it is a day when Arthur has enough money for buying an apartment. He found a great option close to the center of the city with a nice price.

    Plan of the apartment found by Arthur looks like a rectangle n?×?m consisting of squares of size 1?×?1. Each of those squares contains either a wall (such square is denoted by a symbol "*" on the plan) or a free space (such square is denoted on the plan by a symbol ".").

    Room in an apartment is a maximal connected area consisting of free squares. Squares are considered adjacent if they share a common side.

    The old Arthur dream is to live in an apartment where all rooms are rectangles. He asks you to calculate minimum number of walls you need to remove in order to achieve this goal. After removing a wall from a square it becomes a free square. While removing the walls it is possible that some rooms unite into a single one.

    Input

    The first line of the input contains two integers n,?m (1?≤?n,?m?≤?2000) denoting the size of the Arthur apartments.

    Following n lines each contain m symbols — the plan of the apartment.

    If the cell is denoted by a symbol "*" then it contains a wall.

    If the cell is denoted by a symbol "." then it this cell is free from walls and also this cell is contained in some of the rooms.

    Output

    Output n rows each consisting of m symbols that show how the Arthur apartment plan should look like after deleting the minimum number of walls in order to make each room (maximum connected area free from walls) be a rectangle.

    If there are several possible answers, output any of them.

    Sample test(s)

    Input

    5 5
    .*.*.
    *****
    .*.*.
    *****
    .*.*.
    

    Output

    .*.*.
    *****
    .*.*.
    *****
    .*.*.
    

    Input

    6 7
    ***.*.*
    ..*.*.*
    *.*.*.*
    *.*.*.*
    ..*...*
    *******
    

    Output

    ***...*
    ..*...*
    ..*...*
    ..*...*
    ..*...*
    *******
    

    Input

    4 5
    .....
    .....
    ..***
    ..*..
    

    Output

    .....
    .....
    .....
    .....


    題目大意:給一個n*m的矩陣,'' * “表示墻 " . "表示空地,被" * "圍起來的是房間現(xiàn)在求刪去最少的" * "使得每個房間空地的形狀都是一個矩形,輸出刪除后的矩陣


    題目分析:YY一下發(fā)現(xiàn)類似下面這種形狀的(其他可由它翻轉(zhuǎn)或旋轉(zhuǎn)得到)2*2的子矩陣的" * "都要被改成" . "

    *. 
    .. 

    然后就是預(yù)處理一下這種形狀BFS搜一下,用隊(duì)列維護(hù),每次刪去一個" * "分別向周圍8個方向擴(kuò)展,注意要用vis數(shù)組標(biāo)記防止未更新的點(diǎn)重復(fù)入隊(duì)列!


    #include 
    #include 
    #include 
    using namespace std;
    int const MAX = 2005;
    
    int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
    int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
    char map[MAX][MAX];
    bool vis[MAX][MAX];
    int n, m;
    queue  > q;
    
    bool judge(int i, int j)
    {
     if(map[i][j] == '.' || i == 0 || j == 0 || i == n + 1 || j == m + 1)
     return false;
     if(map[i - 1][j - 1] == '.' && map[i - 1][j] == '.' && map[i][j - 1] == '.')
     return true;
     if(map[i + 1][j + 1] == '.' && map[i + 1][j] == '.' && map[i][j + 1] == '.')
     return true;
     if(map[i + 1][j - 1] == '.' && map[i][j - 1] == '.' && map[i + 1][j] == '.')
     return true;
     if(map[i - 1][j + 1] == '.' && map[i - 1][j] == '.' && map[i][j + 1] == '.')
     return true;
     return false;
    }
    
    void BFS()
    {
     while(!q.empty())
     {
     int x = q.front().first;
     int y = q.front().second;
     q.pop();
     map[x][y] = '.';
     for(int i = 0; i < 8; i++)
     {
     int xx = x + dx[i];
     int yy = y + dy[i];
     if(judge(xx, yy) && !vis[xx][yy])
     {
     vis[xx][yy] = true;
     q.push(make_pair(xx, yy));
     }
     }
     }
    }
    
    int main()
    {
     scanf("%d %d", &n, &m);
     for(int i = 1; i <= n; i++)
     scanf("%s", map[i] + 1);
     for(int i = 1; i <= n; i++)
     for(int j = 1; j <= m; j++)
     if(judge(i, j))
     {
     q.push(make_pair(i, j));
     vis[i][j] = true;
     }
     BFS();
     for(int i = 1; i <= n; i++)
     printf("%s\n", map[i] + 1);
    }



    E. Anya and Cubes

    time limit per test:2 seconds

    memory limit per test:256 megabytes


    Anya loves to fold and stick. Today she decided to do just that.

    Anya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has k stickers with exclamation marks. We know that the number of stickers does not exceed the number of cubes.

    Anya can stick an exclamation mark on the cube and get the factorial of the number written on the cube. For example, if a cube reads 5, then after the sticking it reads 5!, which equals 120.

    You need to help Anya count how many ways there are to choose some of the cubes and stick on some of the chosen cubes at most k exclamation marks so that the sum of the numbers written on the chosen cubes after the sticking becomes equal to S. Anya can stick at most one exclamation mark on each cube. Can you do it?

    Two ways are considered the same if they have the same set of chosen cubes and the same set of cubes with exclamation marks.

    Input

    The first line of the input contains three space-separated integers n, k and S (1?≤?n?≤?25, 0?≤?k?≤?n, 1?≤?S?≤?1016) — the number of cubes and the number of stickers that Anya has, and the sum that she needs to get.

    The second line contains n positive integers ai (1?≤?ai?≤?109) — the numbers, written on the cubes. The cubes in the input are described in the order from left to right, starting from the first one.

    Multiple cubes can contain the same numbers.

    Output

    Output the number of ways to choose some number of cubes and stick exclamation marks on some of them so that the sum of the numbers became equal to the given number S.

    Sample test(s)

    Input

    2 2 30
    4 3
    

    Output

    1
    

    Input

    2 2 7
    4 3
    

    Output

    1
    

    Input

    3 1 1
    1 1 1
    

    Output

    6
    

    Note

    In the first sample the only way is to choose both cubes and stick an exclamation mark on each of them.

    In the second sample the only way is to choose both cubes but don't stick an exclamation mark on any of them.

    In the third sample it is possible to choose any of the cubes in three ways, and also we may choose to stick or not to stick the exclamation mark on it. So, the total number of ways is six.

    題目大意:給n個數(shù)a[i],其中可以選出k個將它變成自己的階乘,問有多少種方案取出的數(shù)的和為s


    題目分析:由于n=25,對每個數(shù)有3種情況,不選,選,選它的階乘,因此3^25肯定T,由此想到類似poj 1840這樣的題,我們可以先算前n/2個數(shù)然后用map存儲下來,再算后n/2個數(shù),在后n/2個數(shù)中算出來的數(shù)架設(shè)為sum2如果s-sum2在前n/2個數(shù)的和中出現(xiàn)過,則我們找到相應(yīng)個數(shù)的解,這樣將復(fù)雜度降到2 * 3^12 約等于1e6的數(shù)量級,注意s的范圍是10^16,而18! = 6*10^15因此18以后的階乘我們都不用去算了,搜索的時候當(dāng)然也不用搜,本地跑了好久,交到cf上才500+ms。。


    #include 
    #include 
    #include 
    #include 
    #define ll long long
    using namespace std;
    
    ll fac[20] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 
    3628800, 39916800, 479001600, 6227020800 ,87178291200 ,1307674368000
    ,20922789888000 ,355687428096000 ,6402373705728000};
    ll a[30], s, ans;
    int n, k;
    map  mp[30];
    
    void DFS1(int i, int cnt, ll sum)
    {
     if(sum > s || cnt > k)
     return;
     if(i == n / 2)
     {
     mp[cnt][sum] ++;
     return;
     }
     DFS1(i + 1, cnt, sum);
     DFS1(i + 1, cnt, sum + a[i]);
     if(a[i] <= 18)
     DFS1(i + 1, cnt + 1, sum + fac[a[i]]);
    }
    
    void DFS2(int i, int cnt, ll sum)
    {
     if(sum > s || cnt > k)
     return;
     if(i == n)
     {
     for(int j = 0; j + cnt <= k; j++)
     if(mp[j].count(s - sum))
     ans += mp[j][s - sum];
     return;
     }
     DFS2(i + 1, cnt, sum);
     DFS2(i + 1, cnt, sum + a[i]);
     if(a[i] <= 18)
     DFS2(i + 1, cnt + 1, sum + fac[a[i]]);
    }
    
    int main()
    {
     ans = 0;
     scanf("%d %d %I64d", &n, &k, &s);
     for(int i = 0; i < n; i++)
     scanf("%I64d", &a[i]);
     DFS1(0, 0, 0);
     DFS2(n / 2, 0, 0);
     printf("%I64d\n", ans);
    }




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

    文檔

    CodeforcesRound#297(Div.2)(ABCDE題解)

    CodeforcesRound#297(Div.2)(ABCDE題解):比賽鏈接:http://codeforces.com/contest/525 算是比較簡單的一場了,拖了好久現(xiàn)在才補(bǔ) A. Vitaliy and Pie time limit per test:2 seconds memory limit per test:256 megabytes After a hard day Vitaly
    推薦度:
    標(biāo)簽: abc round 題解
    • 熱門焦點(diǎn)

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 国产办公室秘书无码精品99| 成人精品综合免费视频| 亚洲欧洲美洲无码精品VA| 老司机国内精品久久久久| 亚洲精品无码久久久久去q| 2021年精品国产福利在线| 久久国产精品一国产精品金尊| 久久成人精品| 8050免费午夜一级国产精品| 国产乱码精品一区二区三区中文| 免费看一级毛片在线观看精品视频 | 91精品成人免费国产片| 亚洲av日韩av天堂影片精品| 久久99亚洲综合精品首页| 99久久精品国产一区二区| 国产精品青草久久久久婷婷| 国内精品伊人久久久久av一坑| 综合国产精品第一页| 久久99热这里只有精品国产| 国产叼嘿久久精品久久| 亚洲精品高清视频| www国产精品| 国产精品亚洲片在线| 亚洲高清国产拍精品26U| 人妻少妇看A偷人无码精品视频| 国产精品午夜无码AV天美传媒 | 精品视频在线v| 精品久久8x国产免费观看| 亚洲av午夜成人片精品网站| 日韩精品免费一线在线观看| 精品无码综合一区| 国产微拍精品一区二区| 国产精品伦理久久久久久| 国产成人精品免费大全| 2023国产精品自拍| 777欧美午夜精品影院| www.日韩精品| 国产精品小视频免费无限app| 国产精品国产AV片国产| 国产精品第一页在线| 国产精品自产拍在线观看花钱看|