Codeforces Round #487 (Div. 2)补题博客

71 篇文章 0 订阅


题意 花会像两边掉叶子或者自己就是一个花瓣 判断是不是偶三种花瓣 一个土地上 注意AABBCC

写一半的时候发现有更简单的思路 就是直接找ABC连续就行了


#include <cstdio>
#include <cstring>
using namespace std;
const int MAX_N = 1024;
struct node{
    int a;
    int b;
    int c;
    int cnt;
    char d;
}arr[MAX_N];
char str[MAX_N];
int main(){
    int flag = 0;
    scanf("%s",str);
    int len = strlen(str);
    for(int i=1;i<=len;++i){
        arr[i].d=str[i-1];
        if(arr[i].d=='A'){
        arr[i-1].a=arr[i+1].a=arr[i].a=1;
        }
        if(arr[i].d=='B'){
        arr[i-1].b=arr[i+1].b=arr[i].b=2;
        }
         if(arr[i].d=='C'){
        arr[i-1].c=arr[i+1].c=arr[i].c=3;
        }
    }
    for(int i=1;i<=len;i++){
        arr[i].cnt=arr[i].a+arr[i].b+arr[i].c;
        if(arr[i].cnt==6){
            flag = 1;
            break;
        }
    }
    if(flag) printf("Yes\n");
    else printf("No\n");
    return 0;
}

题意 

给你 n和p 问你这n个字符组成的字符串能不能不成为p为周期的周期串

是周期串 输出No 不是周期串随便输出一组

那么我们先判断是不是周期串 然后在输出的时候特殊操作一下就好 先都变成0 再扫一遍

#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int MAX_N = 1024;
int mp[MAX_N];
struct node{
   char now;
   char former;
}str[MAX_N];
int main(){
    int n,p;
    int flag = 1;
    scanf("%d%d",&n,&p);
    getchar();
    for(int i=0;i<n;++i)
    scanf("%c",&str[i].now);
    for(int i=0;i+p<n;++i){
        if((str[i].now!=str[i+p].now||((str[i].now=='.'&&str[i+p].now!='.')||(str[i].now!='.'&&str[i+p].now=='.')))||(str[i].now=='.'&&str[i+p].now=='.')){
           flag = 0;
           break;
        }
           else {
                flag = 1;
           }
    }

    //printf("|||%d\n",mp[1]);
    //printf("%d\n",flag);
    if(flag==0) {
        for(int i=0;i<n;++i)
            if(str[i].now=='.'){
                str[i].now='0';
                str[i].former='.';
            }
            else continue;
    }
    else printf("No");
    if(flag==0){
    for(int i=0;i+p<n;++i){
        if(str[i].now==str[i+p].now){
            if(str[i].former=='.'){
                str[i].now='1';
            }
            else if(str[i+p].former=='.'){
                str[i+p].now='1';
            }
        }
    }
    for(int i=0;i<n;++i)
        printf("%c",str[i].now);
    }
            printf("\n");
    return 0;
}

C. A Mist of Florescence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
As the boat drifts down the river, a wood full of blossoms shows up on the riverfront.

"I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."

"What is it like?"

"Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"

There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.

The wood can be represented by a rectangular grid of nn rows and mm columns. In each cell of the grid, there is exactly one type of flowers.

According to Mino, the numbers of connected components formed by each kind of flowers are aabbcc and dd respectively. Two cells are considered in the same connected component if and only if a path exists between them that moves between cells sharing common edges and passes only through cells containing the same flowers.

You are to help Kanno depict such a grid of flowers, with nn and mm arbitrarily chosen under the constraints given below. It can be shown that at least one solution exists under the constraints of this problem.

Note that you can choose arbitrary nn and mm under the constraints below, they are not given in the input.

Input

The first and only line of input contains four space-separated integers aabbcc and dd (1a,b,c,d1001≤a,b,c,d≤100) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively.

Output

In the first line, output two space-separated integers nn and mm (1n,m501≤n,m≤50) — the number of rows and the number of columns in the grid respectively.

Then output nn lines each consisting of mm consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and 'D', representing Amaranths, Begonias, Centaureas and Dianthuses, respectively.

In case there are multiple solutions, print any. You can output each letter in either case (upper or lower).

Examples
input
Copy
5 3 2 1
output
Copy
4 7
DDDDDDD
DABACAD
DBABACD
DDDDDDD
input
Copy
50 50 1 1
output
Copy
4 50
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ABABABABABABABABABABABABABABABABABABABABABABABABAB
BABABABABABABABABABABABABABABABABABABABABABABABABA
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
input
Copy
1 6 4 5
output
Copy
7 7
DDDDDDD
DDDBDBD
DDCDCDD
DBDADBD
DDCDCDD
DBDBDDD
DDDDDDD
Note

In the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.


下面这图是一个很好的思路
首先我们把abcd都减减 那么下面我们要做的事情就是4个25*25的区间联通快填满A B C D
然后然后隔空插你需要的   比如在A插B B插C C插D D插A
代码实现
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
const int MAX_N = 124;
char mp[MAX_N][MAX_N];
int main(){
   int a,b,c,d;
   scanf("%d%d%d%d",&a,&b,&c,&d);
   a--,b--,c--,d--;
   int pos=1,k=1;
   while(d){
   if(d>=12){
        if(k==1){
   for(int i=1;i<25;i+=2)
        mp[pos][i]='D';
        pos+=2;
        d-=12;
        k--;
        }
        else if(k==0){
        for(int i=2;i<=25;i+=2)
        mp[pos][i]='D';
        pos+=2;
        d-=12;
        k++;
        }
        }
   else{
        if(k==1){
    for(int i=1;i<1+d*2;i+=2)
        mp[pos][i]='D';
        d=0;
        }
        if(k==0){
        for(int i=2;i<2+d*2;i+=2)
        mp[pos][i]='D';
        d=0;
        }
   }
   }
   pos = 1;
   k=1;
      while(c){
   if(c>=12){
       if(k==1){
   for(int i=26;i<50;i+=2)
        mp[pos][i]='C';
        pos+=2;
        c-=12;
        k--;
       }
        else if(k==0){
   for(int i=27;i<=50;i+=2)
        mp[pos][i]='C';
        pos+=2;
        c-=12;
        k++;
       }
   }
   else{
        if(k==1){
    for(int i=26;i<26+c*2;i+=2)
        mp[pos][i]='C';
        c=0;
        }
        if(k==0){
        for(int i=27;i<27+c*2;i+=2)
        mp[pos][i]='C';
        c=0;
        }
   }
   }
   pos = 26;
   k=1;
      while(b){
   if(b>=12){
       if(k==1){
   for(int i=1;i<25;i+=2)
        mp[pos][i]='B';
        pos+=2;
        b-=12;
        k--;
       }
       else if(k==0){
        for(int i=2;i<=25;i+=2)
        mp[pos][i]='B';
        pos+=2;
        b-=12;
        k++;
       }
   }
   else{
        if(k==1){
    for(int i=1;i<1+b*2;i+=2)
        mp[pos][i]='B';
        b=0;
        }
        if(k==0){
        for(int i=2;i<1+b*2;i+=2)
        mp[pos][i]='B';
        b=0;
        }
   }
   }
   pos = 26;
   k=1;
      while(a){
   if(a>=12){
        if(k==1){
   for(int i=26;i<50;i+=2)
        mp[pos][i]='A';
        pos+=2;
        a-=12;
        k--;
        }
        else if(k==0){
        for(int i=27;i<=50;i+=2)
        mp[pos][i]='A';
        pos+=2;
        a-=12;
        k++;
        }
   }
   else{
        if(k==1){
    for(int i=26;i<26+a*2;i+=2)
        mp[pos][i]='A';
        a=0;
        }
        if(k==0){
        for(int i=27;i<27+a*2;i+=2)
        mp[pos][i]='A';
        a=0;
        }
   }
   }
   printf("50 50\n");
   for(int i=1;i<=50;i++){
    for(int j=1;j<=50;j++){
        if(i<=25&&j<=25){
            if(mp[i][j]=='D') printf("%c",mp[i][j]);
            else printf("A");
        }
        if(i<=25&&j>25){
            if(mp[i][j]=='C') printf("%c",mp[i][j]);
            else printf("B");
            if(j==50) printf("\n");
        }
        if(i>25&&j<=25){
            if(mp[i][j]=='B') printf("%c",mp[i][j]);
            else printf("C");

        }
        if(i>25&&j>25){
            if(mp[i][j]=='A') printf("%c",mp[i][j]);
            else printf("D");
            if(j==50) printf("\n");
        }
    }
   }

   return 0;
}



学算法两个月以来第一次碰到的构造题
这是我原来的代码
#include <cstdio>
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;

char pic[55][55];
int main()
{
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int pos=0;
    while(a)
    {
        if(a>=25)
        {
            for(int i=0;i<50;i+=2) pic[pos][i]='A';
            for(int i=1;i<50;i+=2) pic[pos][i]='B';
            a-=25;
            pos++;
             for(int i=0;i<50;i++) pic[pos][i]='B';
            pos++;
        }
        else
        {
            for(int i=0;i<50;i++)   pic[pos][i]='B';
            for(int i=0;i<a*2;i+=2) pic[pos][i]='A';
            pos++;
            for(int i=0;i<50;i++) pic[pos][i]='B';
            pos++;
            break;
        }
    }
    for(int i=0;i<50;i++) pic[pos][i]='C';
    pos++;
    b--;
    while(b)
    {
        if(b>25)
        {
            for(int i=0;i<50;i+=2) pic[pos][i]='B';
            for(int i=1;i<50;i+=2) pic[pos][i]='C';
            b-=25;
            pos++;
            for(int i=0;i<50;i++) pic[pos][i]='C';
            pos++;
        }
        else
        {
            for(int i=0;i<50;i++)   pic[pos][i]='C';
            for(int i=0;i<b*2;i+=2) pic[pos][i]='B';
            pos++;
            for(int i=0;i<50;i++) pic[pos][i]='C';
            pos++;
            break;
        }
    }
    c--;
    for(int i=0;i<50;i++) pic[pos][i]='D';
    if(c==0) pic[pos][0]='C';
    pos++;
    while(c)
    {
        if(c>25)
        {
            for(int i=0;i<50;i+=2) pic[pos][i]='C';
            for(int i=1;i<50;i+=2) pic[pos][i]='D';
            c-=25;
            pos++;
            for(int i=0;i<50;i++) pic[pos][i]='D';
            pos++;
        }
        else
        {
            for(int i=0;i<50;i++)   pic[pos][i]='D';
            for(int i=0;i<c*2;i+=2) pic[pos][i]='C';
            pos++;
            pic[pos][0]='C';
            for(int i=1;i<50;i++) pic[pos][i]='D';
            pos++;
            break;
        }
    }
    for(int i=0;i<50;i++) pic[pos][i]='C';
    pos++;
    d--;
    while(d)
    {
        if(d>25)
        {
            for(int i=0;i<50;i+=2) pic[pos][i]='D';
            for(int i=1;i<50;i+=2) pic[pos][i]='C';
            d-=25;
            pos++;
            for(int i=0;i<50;i++) pic[pos][i]='C';
            pos++;
        }
        else
        {
            for(int i=0;i<50;i++)   pic[pos][i]='C';
            for(int i=0;i<d*2;i+=2) pic[pos][i]='D';
            pos++;
            for(int i=0;i<50;i++) pic[pos][i]='C';
            pos++;
            break;
        }
    }
    cout<<pos<<" "<<50<<endl;
    for(int i=0;i<pos;i++)
    {
        for(int j=0;j<50;j++)
            cout<<pic[i][j];
        cout<<endl;
    }
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}
D. A Shade of Moonlight
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Gathering darkness shrouds the woods and the world. The moon sheds its light on the boat and the river.

"To curtain off the moonlight should be hardly possible; the shades present its mellow beauty and restful nature." Intonates Mino.

"See? The clouds are coming." Kanno gazes into the distance.

"That can't be better," Mino turns to Kanno.

The sky can be seen as a one-dimensional axis. The moon is at the origin whose coordinate is 00.

There are nn clouds floating in the sky. Each cloud has the same length ll. The ii-th initially covers the range of (xi,xi+l)(xi,xi+l) (endpoints excluded). Initially, it moves at a velocity of vivi, which equals either 11 or 1−1.

Furthermore, no pair of clouds intersect initially, that is, for all 1i<jn1≤i<j≤n|xixj|l|xi−xj|≥l.

With a wind velocity of ww, the velocity of the ii-th cloud becomes vi+wvi+w. That is, its coordinate increases by vi+wvi+w during each unit of time. Note that the wind can be strong and clouds can change their direction.

You are to help Mino count the number of pairs (i,j)(i,j) (i<ji<j), such that with a proper choice of wind velocity ww not exceeding wmaxwmax in absolute value (possibly negative and/or fractional), the ii-th and jj-th clouds both cover the moon at the same future moment. This wwdoesn't need to be the same across different pairs.

Input

The first line contains three space-separated integers nnll, and wmaxwmax (1n1051≤n≤1051l,wmax1081≤l,wmax≤108) — the number of clouds, the length of each cloud and the maximum wind speed, respectively.

The ii-th of the following nn lines contains two space-separated integers xixi and vivi (108xi108−108≤xi≤108vi{1,1}vi∈{−1,1}) — the initial position and the velocity of the ii-th cloud, respectively.

The input guarantees that for all 1i<jn1≤i<j≤n|xixj|l|xi−xj|≥l.

Output

Output one integer — the number of unordered pairs of clouds such that it's possible that clouds from each pair cover the moon at the same future moment with a proper choice of wind velocity ww.

Examples
input
Copy
5 1 2
-2 1
2 1
3 -1
5 -1
7 -1
output
Copy
4
input
Copy
4 10 1
-20 1
-10 -1
0 1
10 -1
output
Copy
1
Note

In the first example, the initial positions and velocities of clouds are illustrated below.

The pairs are:

  • (1,3)(1,3), covering the moon at time 2.52.5 with w=0.4w=−0.4;
  • (1,4)(1,4), covering the moon at time 3.53.5 with w=0.6w=−0.6;
  • (1,5)(1,5), covering the moon at time 4.54.5 with w=0.7w=−0.7;
  • (2,5)(2,5), covering the moon at time 2.52.5 with w=2w=−2.

Below is the positions of clouds at time 2.52.5 with w=0.4w=−0.4. At this moment, the 11-st and 33-rd clouds both cover the moon.

In the second example, the only pair is (1,4)(1,4), covering the moon at time 1515 with w=0w=0.

Note that all the times and wind velocities given above are just examples among infinitely many choices.


挖坑留着补题
E. A Trance of Nightfall
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
The cool breeze blows gently, the flowing water ripples steadily.

"Flowing and passing like this, the water isn't gone ultimately; Waxing and waning like that, the moon doesn't shrink or grow eventually."

"Everything is transient in a way and perennial in another."

Kanno doesn't seem to make much sense out of Mino's isolated words, but maybe it's time that they enjoy the gentle breeze and the night sky — the inexhaustible gifts from nature.

Gazing into the sky of stars, Kanno indulges in a night's tranquil dreams.

There is a set SS of nn points on a coordinate plane.

Kanno starts from a point PP that can be chosen on the plane. PP is not added to SS if it doesn't belong to SS. Then the following sequence of operations (altogether called a move) is repeated several times, in the given order:

  1. Choose a line ll such that it passes through at least two elements in SS and passes through Kanno's current position. If there are multiple such lines, one is chosen equiprobably.
  2. Move to one of the points that belong to SS and lie on ll. The destination is chosen equiprobably among all possible ones, including Kanno's current position (if it does belong to SS).

There are qq queries each consisting of two integers (ti,mi)(ti,mi). For each query, you're to help Kanno maximize the probability of the stopping position being the titi-th element in SS after mimi moves with a proper selection of PP, and output this maximum probability. Note that according to rule 1, PP should belong to at least one line that passes through at least two points from SS.

Input

The first line contains a positive integer nn (2n2002≤n≤200) — the number of points in SS.

The ii-th of the following nn lines contains two space-separated integers xixi and yiyi (104xi,yi104−104≤xi,yi≤104) — the coordinates of the ii-th point in SS. The input guarantees that for all 1i<jn1≤i<j≤n(xi,yi)(xj,yj)(xi,yi)≠(xj,yj) holds.

The next line contains a positive integer qq (1q2001≤q≤200) — the number of queries.

Each of the following qq lines contains two space-separated integers tt and mm (1tin1≤ti≤n1mi1041≤mi≤104) — the index of the target point and the number of moves, respectively.

Output

Output qq lines each containing a decimal number — the ii-th among them denotes the maximum probability of staying on the titi-th point after mimi steps, with a proper choice of starting position PP.

Your answer will be considered correct if each number in your output differs from the corresponding one in jury's answer by at most 10610−6.

Formally, let your answer be aa, and the jury's answer be bb. Your answer is considered correct if |ab|106|a−b|≤10−6.

Example
input
Copy
5
0 0
1 3
2 2
3 1
4 4
10
1 1
2 1
3 1
4 1
5 1
3 2
3 3
3 4
3 5
3 6
output
Copy
0.50000000000000000000
0.50000000000000000000
0.33333333333333331483
0.50000000000000000000
0.50000000000000000000
0.18518518518518517491
0.15226337448559670862
0.14494741655235482414
0.14332164812274550414
0.14296036624949901017
Note

The points in SS and possible candidates for line ll are depicted in the following figure.

For the first query, when P=(1,3)P=(−1,−3)ll is uniquely determined to be 3x=y3x=y, and thus Kanno will move to (0,0)(0,0) with a probability of 1212.

For the third query, when P=(2,2)P=(2,2)ll is chosen equiprobably between x+y=4x+y=4 and x=yx=y. Kanno will then move to the other four points with a probability of 1213=1612⋅13=16 each, or stay at (2,2)(2,2) with a probability of 1313.

挖坑留着补题


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值