日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Educational Codeforces Round 37 (Rated for Div. 2)

發布時間:2025/3/18 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Educational Codeforces Round 37 (Rated for Div. 2) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我的代碼應該不會被hack,立個flag

A. Water The Garden time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

It is winter now, and Max decided it's about time he watered the garden.

The garden can be represented as?n?consecutive garden beds, numbered from?1?to?n.?k?beds contain water taps (i-th tap is located in the bed?xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed?xi?is turned on, then after one second has passed, the bed?xi?will be watered; after two seconds have passed, the beds from the segment?[xi?-?1,?xi?+?1]?will be watered (if they exist); after?j?seconds have passed?(j?is an integer number), the beds from the segment?[xi?-?(j?-?1),?xi?+?(j?-?1)]?will be watered (if they exist).?Nothing changes during the seconds, so, for example, we can't say that the segment?[xi?-?2.5,?xi?+?2.5]?will be watered after?2.5seconds have passed; only the segment?[xi?-?2,?xi?+?2]?will be watered at that moment.

The garden from test?1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.The garden from test?1?after?2?seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed.

Max wants to?turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!

Input

The first line contains one integer?t?— the number of test cases to solve (1?≤?t?≤?200).

Then?t?test cases follow. The first line of each test case contains two integers?n?and?k?(1?≤?n?≤?200,?1?≤?k?≤?n) — the number of garden beds and water taps, respectively.

Next line contains?k?integers?xi?(1?≤?xi?≤?n) — the location of?i-th water tap. It is guaranteed that for each??condition?xi?-?1?<?xiholds.

It is guaranteed that the sum of?n?over all test cases doesn't exceed?200.

Note that in hacks you have to set?t?=?1.

Output

For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.

Example input 3
5 1
3
3 3
1 2 3
4 1
1 output 3
1
4 Note

The first example consists of?3?tests:

  • There are?5?garden beds, and a water tap in the bed?3. If we turn it on, then after?1?second passes, only bed?3?will be watered; after?2seconds pass, beds?[1,?3]?will be watered, and after?3?seconds pass, everything will be watered.
  • There are?3?garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after?1?second passes.
  • There are?4?garden beds, and only one tap in the bed?1. It will take?4?seconds to water, for example, bed?4.
  • A題意很長是個模擬,自己也迷了好久,枚舉每個點就可以了

    #include<bits/stdc++.h> using namespace std; int a[205],b[205]; int main() {ios::sync_with_stdio(false);int t;cin>>t;while(t--){memset(b,0,sizeof(b));int n,k,ma=0;cin>>n>>k;for(int i=0; i<k; i++)cin>>a[i],b[a[i]]=1;for(int i=1; i<=n; i++){int sum=1,tl=i,tr=i;while(b[tl]!=1&&b[tr]!=1){if(tl-1>0)tl--;if(tr+1<=n)tr++;sum++;}ma=max(ma,sum);}cout<<ma<<endl;}return 0; }

    qls的代碼超級優秀的,媽耶,長知識

    #include<bits/stdc++.h> using namespace std; const int MAXN=205; int x[MAXN]; int main() {int T;scanf("%d",&T);while(T--){int n,k;scanf("%d%d",&n,&k);for(int i=1;i<=k;i++)scanf("%d",&x[i]);int res=0;for(int i=1;i<=n;i++){int mi=n;for(int j=1;j<=k;j++)mi=min(mi,abs(i-x[j]));res=max(res,mi);}printf("%d\n",res+1);}return 0; } B. Tea Queue time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

    Recently?n?students from city S moved to city P to attend a programming camp.

    They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.

    i-th student comes to the end of the queue at the beginning of?li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of?ri-th second student?i?still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.

    For each student determine the second he will use the teapot and get his tea (if he actually gets it).

    Input

    The first line contains one integer?t?— the number of test cases to solve (1?≤?t?≤?1000).

    Then?t?test cases follow. The first line of each test case contains one integer?n?(1?≤?n?≤?1000) — the number of students.

    Then?n?lines follow. Each line contains two integer?li,?ri?(1?≤?li?≤?ri?≤?5000) — the second?i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.

    It is guaranteed that for every??condition?li?-?1?≤?li?holds.

    The sum of?n?over all test cases doesn't exceed?1000.

    Note that in hacks you have to set?t?=?1.

    Output

    For each test case print?n?integers.?i-th of them must be equal to the second when?i-th student gets his tea, or?0?if he leaves without tea.

    Example input 2
    2
    1 3
    1 4
    3
    1 5
    1 1
    2 3 output 1 2
    1 0 2 Note

    The example contains?2?tests:

  • During?1-st second, students?1?and?2?come to the queue, and student?1?gets his tea. Student?2?gets his tea during?2-nd second.
  • During?1-st second, students?1?and?2?come to the queue, student?1?gets his tea, and student?2?leaves without tea. During?2-nd second, student?3?comes and gets his tea.
  • ?n個人排隊,有進隊時間和出隊時間,進隊時間相同的話,編號小的優先

    隊列或者數組模擬吧

    #include<bits/stdc++.h> using namespace std; int l[1005],r[1005],M[1005]; int main() {ios::sync_with_stdio(false);int T;cin>>T;while(T--){int n;cin>>n;memset(M,0,sizeof M);for(int i=1; i<=n; i++)cin>>l[i]>>r[i];int tot=1;queue<int> q;for(int i=1; i<=5000; i++){while(tot<=n&&l[tot]==i)q.push(tot++);while(q.size()&&r[q.front()]<i)q.pop();if(q.size()){int tmp=q.front();q.pop();M[tmp]=i;}}for(int i=1; i<=n; i++)cout<<M[i]<<" ";cout<<"\n";}return 0; }

    vector的

    #include<bits/stdc++.h> using namespace std; vector<pair<int,pair<int,int> > >V; int M[1005]; int main() {ios::sync_with_stdio(false);int T;cin>>T;while(T--){V.clear();int n;cin>>n;memset(M,0,sizeof M);for(int i=1,l,r; i<=n; i++)cin>>l>>r,V.push_back(make_pair(l,make_pair(i,r)));sort(V.begin(),V.end());int j=0,l=n;for(int i=1; i<= 5000&&j<n; i++){while((V[j].second).second<i&&j<n)j++;if(V[j].first<=i)M[(V[j].second).first]=i,j++;}for(int i=1; i<=n; i++)cout<<M[i]<<" ";cout<<"\n";}return 0; }

    qls很優秀的代碼

    #include<bits/stdc++.h> using namespace std; int main() {int T;scanf("%d",&T);while(T--){int n;scanf("%d",&n);int now=1;for(int i=1;i<=n;i++){int l,r;scanf("%d%d",&l,&r);if(now>r)printf("0");else{now=max(now,l);printf("%d",now++);}printf("%c"," \n"[i==n]);}}return 0; } C. Swap Adjacent Elements time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

    You have an array?a?consisting of?n?integers. Each integer from?1?to?n?appears exactly once in this array.

    For some indices?i?(1?≤?i?≤?n?-?1) it is possible to swap?i-th element with?(i?+?1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the number of times you swap?i-th element with?(i?+?1)-th (if the position is not forbidden).

    Can you make this array sorted in ascending order performing some sequence of swapping operations?

    Input

    The first line contains one integer?n?(2?≤?n?≤?200000) — the number of elements in the array.

    The second line contains?n?integers?a1,?a2, ...,?an?(1?≤?ai?≤?200000) — the elements of the array. Each integer from?1?to?n?appears exactly once.

    The third line contains a string of?n?-?1?characters, each character is either?0?or?1. If?i-th character is?1, then you can swap?i-th element with?(i?+?1)-th any number of times, otherwise it is forbidden to swap?i-th element with?(i?+?1)-th.

    Output

    If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print?YES. Otherwise, print?NO.

    Examples input 6
    1 2 5 3 4 6
    01110 output YES input 6
    1 2 5 3 4 6
    01010 output NO Note

    In the first example you may swap?a3?and?a4, and then swap?a4?and?a5.

    ?

    ?交換相鄰的其實就是在排序啊,所以出現連續的1就去sort好了

    #include<bits/stdc++.h> using namespace std; int a[200005]; int main() {int n;while(cin>>n){int f=1;string s;for(int i=1;i<=n;i++)cin>>a[i];cin>>s;ios::sync_with_stdio(false);int l=0,r=0;for(int i=0;s[i];i++){if(s[i]=='0')continue;l=i;for(;s[i];i++){if(s[i]=='0')break;r=i;}sort(a+l+1,a+r+3);}for(int i=1;i<=n&&f;i++)if(a[i]!=i)f=0;if(f)cout<<"YES\n";else cout<<"NO\n";}return 0; }

    ?

    E. Connected Components? time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

    You are given an undirected graph consisting of?n?vertices and??edges. Instead of giving you the edges that exist in the graph, we give you?m?unordered pairs (x,?y) such that there is no edge between?x?and?y, and if some pair of vertices is not listed in the input, then there is an edge between these vertices.

    You have to find the number of connected components in the graph and the size of each component. A connected component is a set of vertices?X?such that for every two vertices from this set there exists at least one path in the graph connecting these vertices, but adding any other vertex to?X?violates this rule.

    Input

    The first line contains two integers?n?and?m?(1?≤?n?≤?200000,?).

    Then?m?lines follow, each containing a pair of integers?x?and?y?(1?≤?x,?y?≤?n,?x?≠?y) denoting that?there is no edge?between?x?and?y. Each pair is listed at most once; (x,?y) and (y,?x) are considered the same (so they are never listed in the same test). If some pair of vertices is not listed in the input, then there?exists?an edge between those vertices.

    Output

    Firstly print?k?— the number of connected components in this graph.

    Then print?k?integers — the sizes of components. You should output these integers in non-descending order.

    Example input Copy 5 5
    1 2
    3 4
    3 2
    4 2
    2 5 output 2
    1 4 E是個圖論,可以bfs出序列 #include<bits/stdc++.h> using namespace std; const int N=2e5+5; set<int>M[N+N]; queue<int>Q; int q[N],yy[N],n,m,k; void bfs() {while(!Q.empty()){int tot=1,u=Q.front();Q.pop();q[0]=u;for(int i=0; i<tot; i++){int now=n-tot;while(now>0&&!Q.empty()){int v=Q.front();Q.pop();if(!M[q[i]].count(v)) q[tot++]=v;else Q.push(v);--now;}}yy[k++]=tot;} } int main() {ios::sync_with_stdio(false);cin>>n>>m;for(int i=0,u,v; i<m; i++)cin>>u>>v,M[u].insert(v),M[v].insert(u);for(int i=1; i<=n; i++) Q.push(i);bfs();sort(yy,yy+k);printf("%d\n",k);for(int i=0; i<k; i++)printf("%d ",yy[i]);return 0; }

    ?

    轉載于:https://www.cnblogs.com/BobHuang/p/8408838.html

    與50位技術專家面對面20年技術見證,附贈技術全景圖

    總結

    以上是生活随笔為你收集整理的Educational Codeforces Round 37 (Rated for Div. 2)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 中文字幕有码在线播放 | 性歌舞团一区二区三区视频 | youjizz.com最新| 91网站免费视频 | 在线观看www视频 | 成人18视频 | 久久精品性 | 国产a精品| 日本久久综合网 | 精品日韩一区二区三区四区 | www婷婷 | 另类av在线 | www.com在线观看 | 欧美色图视频在线 | 久久久久久久久久久久久久久久久久 | 97精品超碰一区二区三区 | 看毛片看毛片 | 性农村xxxxx小树林 | 小妹色播影院 | 欧洲美女与动交zozzo | 久久免费播放 | 影院色原网站 | 国产欧美综合一区 | 国产欲妇 | 日精品 | 性网爆门事件集合av | 精品视频一区二区三区在线观看 | 羞视频在线观看 | 日韩欧美一区二区在线 | www.97超碰| 99er精品视频 | 在线免费观看av网 | 国产成人在线免费观看 | 国产精品久久福利 | 国产成人精品影院 | 成人午夜av在线 | 日韩欧美网站 | 欧美亚洲第一区 | 懂色一区二区三区 | 久久亚洲少妇 | 国产男女猛烈无遮挡免费观看网站 | 那个网站可以看毛片 | 久久久久亚洲AV成人网人人小说 | 久久澡 | xxxxx69| jzzijzzij日本成熟少妇 | 日韩sese| 中文 日韩 欧美 | 国产亚洲欧美在线视频 | 乱色精品无码一区二区国产盗 | 精品国精品国产 | 国内三级视频 | 男女啪啪免费看 | 亚洲欧美激情视频 | 性色欲网站人妻丰满中文久久不卡 | 在线视频观看 | 欧美精品久久久久久久多人混战 | 日韩中文av | 免费一级毛片麻豆精品 | 偷拍青青草 | 性欧美18一19内谢 | 日本少妇性生活 | 美女在线免费视频 | 艹男人的日日夜夜 | 巨胸爆乳美女露双奶头挤奶 | 亚洲乱码少妇 | 超碰久操| 一区二区三区四区在线 | 日日碰| 国产三级大片 | 欧美粉嫩videosex极品 | 欧美成人视屏 | 国产91久久精品一区二区 | 黄色录像片子 | 91丝袜一区二区三区 | av在线免费网址 | 日韩一区二区三区在线播放 | 成人做爰黄 | 激情久久久久 | 国产高清av | 国产欧美激情在线观看 | 色先锋av资源 | 天天天干 | 原来神马电影免费高清完整版动漫 | 日本爽妇网| 制服师生在线 | 日本人妻一区二区三区 | 久久久久久a | 国产精品一二三级 | 先锋影音制服丝袜 | 午夜婷婷色 | 人妻奶水人妻系列 | 原创真实夫妻啪啪av | 亚洲视频播放 | 裸体av淫导航 | 操极品少妇 | 国产乱free国语对白 | 精品无码三级在线观看视频 | 超黄网站在线观看 |