codeforces(round534)div2总结

本文深入探讨了四道编程竞赛题目,包括数字拆分、字符串游戏、网格游戏及模运算游戏,提供了详细的解题思路与代码实现,是提升编程竞赛技能的实用指南。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

T A

题目
A. Splitting into digits
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Vasya has his favourite number nn. He wants to split it to some non-zero digits. It means, that he wants to choose some digits d1,d2,…,dkd1,d2,…,dk, such that 1≤di≤91≤di≤9 for all ii and d1+d2+…+dk=nd1+d2+…+dk=n.

Vasya likes beauty in everything, so he wants to find any solution with the minimal possible number of different digits among d1,d2,…,dkd1,d2,…,dk. Help him!

Input
The first line contains a single integer nn — the number that Vasya wants to split (1≤n≤10001≤n≤1000).

Output
In the first line print one integer kk — the number of digits in the partition. Note that kk must satisfy the inequality 1≤k≤n1≤k≤n. In the next line print kk digits d1,d2,…,dkd1,d2,…,dk separated by spaces. All digits must satisfy the inequalities 1≤di≤91≤di≤9.

You should find a partition of nn in which the number of different digits among d1,d2,…,dkd1,d2,…,dk will be minimal possible among all partitions of nn into non-zero digits. Among such partitions, it is allowed to find any. It is guaranteed that there exists at least one partition of the number nn into digits.

Examples
inputCopy
1
outputCopy
1
1
inputCopy
4
outputCopy
2
2 2
inputCopy
27
outputCopy
3
9 9 9
Note
In the first test, the number 11 can be divided into 11 digit equal to 11.

In the second test, there are 33 partitions of the number 44 into digits in which the number of different digits is 11. This partitions are [1,1,1,1][1,1,1,1], [2,2][2,2] and [4][4]. Any of these partitions can be found. And, for example, dividing the number 44 to the digits [1,1,2][1,1,2] isn’t an answer, because it has 22 different digits, that isn’t the minimum possible number.

就是一道水题,将一个数字拆成很多数字,使得不同的数字最少,那么显而易见,全拆成1就没有不一样的
代码

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define MAXN 100010
using namespace std;
int n;
int main()
  {
    int i,j,k;
    scanf("%d",&n);
    printf("%d\n",n);
    for(i=1;i<=n;i++)
      printf("1 ");
    return 0;
  }

T B

题目
B. Game with string
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Two people are playing a game with a string ss, consisting of lowercase latin letters.

On a player’s turn, he should choose two consecutive equal letters in the string and delete them.

For example, if the string is equal to “xaax” than there is only one possible turn: delete “aa”, so the string will become “xx”. A player not able to make a turn loses.

Your task is to determine which player will win if both play optimally.

Input
The only line contains the string ss, consisting of lowercase latin letters (1≤|s|≤1000001≤|s|≤100000), where |s||s| means the length of a string ss.

Output
If the first player wins, print “Yes”. If the second player wins, print “No”.

Examples
inputCopy
abacaba
outputCopy
No
inputCopy
iiq
outputCopy
Yes
inputCopy
abba
outputCopy
No
Note
In the first example the first player is unable to make a turn, so he loses.

In the second example first player turns the string into “q”, then second player is unable to move, so he loses.
对于这道题,无论怎么拿,可以删掉的个数一定是一定的,那么假设我已知一共可以拿掉n次,那么如果n是奇数,那么对面必死,如果是偶数,那么我必死,接下来就是计算,一共有多少个这种“对”可以拿掉,我首先想到了暴力,不停地循环,有这种两个在一块的就删除计算答案,那么我想到这样做的时间复杂度似乎是o(n^2)问题就在于对于每次找到一个位置的左边一个位置访问了大量不必要访问的空间(已经删除过了的)换成链表,这样复杂度就是o(n)
代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define MAXN 100010
using namespace std;
int l[MAXN],r[MAXN],ans,n;
bool book[MAXN];
int main()
  {
    int i,j,k;
    string s;
    cin>>s;  
    s=" "+s;
    n=s.length();
    for(i=1;i<n;i++)
     {
       l[i]=i-1;
       r[i]=i+1;
     }//abba
    for(i=2;i<=n;i++)
     {
       int pos1=l[i],pos2=i;
       if(s[pos1]==s[pos2])
         {
           ans++;
           l[pos2+1]=l[pos1];  
         }
     }   
    if(ans%2==1){printf("Yes");return 0;}
    else {printf("No");return 0;}
    return 0;
  }

T C

题目
C. Grid game
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is placed, each cell which is located in fully occupied row or column is deleted (cells are deleted at the same time independently). You can place tile in the grid at any position, the only condition is that tiles (and tile parts) should not overlap. Your goal is to proceed all given figures and avoid crossing at any time.

Input
The only line contains a string ss consisting of zeroes and ones (1≤|s|≤10001≤|s|≤1000). Zero describes vertical tile, one describes horizontal tile.

Output
Output |s||s| lines — for each tile you should output two positive integers r,cr,c, not exceeding 44, representing numbers of smallest row and column intersecting with it.

If there exist multiple solutions, print any of them.

Example
inputCopy
010
outputCopy
1 1
1 2
1 4
Note
Following image illustrates the example after placing all three tiles:

Then the first row is deleted:

对于这道题,我首先想到,如果竖着的棋或横着的棋够两个的话,那么就可以完美消除,所以最后只需要根据题目给的顺序放棋就ok了,对于给定的放棋顺序,第一个竖着的我放在1,1,第一个横着的我放在3,3,那么第二个横着的或者是竖着的都可以放在3,1,而不会影响,这个提就这样ok了。
代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define MAXN 100010
using namespace std;
int main()
   {
      int i,j,k,t1=0,t2=0;
      string s;
      cin>>s;
      for(i=0;i<s.length();i++)
        {
           if(s[i]=='1')
            {
               t1++;
               t1%=2;
               if(t1==1)
                 {
                    printf("3 3\n");       
                 }   
               else 
                 {
                    printf("3 1\n");    
                 }         
            }  
           else 
            {
               t2++;
               t2%=2;
               if(t2==1)
                 {
                    printf("1 1\n");       
                 }      
               else 
                 {
                    printf("3 1\n");       
                 }
            }                     
        } 
     return 0;      

T D

题目
D. Game with modulo
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
This is an interactive problem.

Vasya and Petya are going to play the following game: Petya has some positive integer number aa. After that Vasya should guess this number using the following questions. He can say a pair of non-negative integer numbers (x,y)(x,y). Petya will answer him:

“x”, if (xmoda)≥(ymoda)(xmoda)≥(ymoda).
“y”, if (xmoda)<(ymoda)(xmoda)<(ymoda).
We define (xmoda)(xmoda) as a remainder of division xx by aa.

Vasya should guess the number aa using no more, than 60 questions.

It’s guaranteed that Petya has a number, that satisfies the inequality 1≤a≤1091≤a≤109.

Help Vasya playing this game and write a program, that will guess the number aa.

Interaction
Your program should play several games.

Before the start of any game your program should read the string:

“start” (without quotes) — the start of the new game.
“mistake” (without quotes) — in the previous game, you found the wrong answer. Your program should terminate after reading this string and it will get verdict “Wrong answer”.
“end” (without quotes) — all games finished. Your program should terminate after reading this string.
After reading the string “start” (without quotes) the new game starts.

At the beginning, your program should ask several questions about pairs of non-negative integer numbers (x,y)(x,y). You can only ask the numbers, that satisfy the inequalities 0≤x,y≤2⋅1090≤x,y≤2⋅109. To ask a question print “? x y” (without quotes). As the answer, you should read one symbol:

“x” (without quotes), if (xmoda)≥(ymoda)(xmoda)≥(ymoda).
“y” (without quotes), if (xmoda)<(ymoda)(xmoda)<(ymoda).
“e” (without quotes) — you asked more than 6060 questions. Your program should terminate after reading this string and it will get verdict “Wrong answer”.
After your program asked several questions your program should print the answer in form “! a” (without quotes). You should print the number aa satisfying the inequalities 1≤a≤1091≤a≤109. It’s guaranteed that Petya’s number aa satisfied this condition. After that, the current game will finish.

We recall that your program can’t ask more than 6060 questions during one game.

If your program doesn’t terminate after reading “mistake” (without quotes), “end” (without quotes) or “e” (without quotes), it can get any verdict, because it will continue reading from closed input. Also, if your program prints answer or question in the incorrect format it can get any verdict, too. Be careful.

Don’t forget to flush the output after printing questions and answers.

To flush the output, you can use:

fflush(stdout) in C++.
System.out.flush() in Java.
stdout.flush() in Python.
flush(output) in Pascal.
See the documentation for other languages.
It’s guaranteed that you should play at least 11 and no more than 100100 games.

Hacks:

In hacks, you can use only one game. To hack a solution with Petya’s number aa (1≤a≤1091≤a≤109) in the first line you should write a single number 11 and in the second line you should write a single number aa.

Example
inputCopy
start
x
x
start
x
x
y
start
x
x
y
y
end
outputCopy
? 0 0
? 10 1
! 1
? 0 0
? 3 4
? 2 5
! 2
? 2 4
? 2 5
? 3 10
? 9 1
! 3
Note
In the first test, you should play 33 games with Petya’s numbers 11, 22 and 33.

In the first game, Petya will answer “x” (without quotes) to any question, because (xmod1)=0(xmod1)=0 for any integer xx.

In the second game, if you will ask pair (0,0)(0,0), the answer will be “x” (without quotes), because (0mod2)≥(0mod2)(0mod2)≥(0mod2). But if you will ask pair (2,5)(2,5), the answer will be “y” (without quotes), because (2mod2)<(5mod2)(2mod2)<(5mod2), because (2mod2)=0(2mod2)=0 and (5mod2)=1(5mod2)=1.
这道题昨天时间不够,先mark下来过几天补

T E

题目
这道题暂时还不会

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值