首页 > 其他分享 >2025.1.21——1300

2025.1.21——1300

时间:2025-01-22 11:21:53浏览次数:1  
标签:2025.1 21 int make texttt ice test 1300 cream

2025.1.21——1300


A 1300

Qingshan has a string \(s\) which only contains \(\texttt{0}\) and \(\texttt{1}\).

A string \(a\) of length \(k\) is good if and only if

  • \(a_i \ne a_{k-i+1}\) for all \(i=1,2,\ldots,k\).

For Div. 2 contestants, note that this condition is different from the condition in problem B.

For example, \(\texttt{10}\), \(\texttt{1010}\), \(\texttt{111000}\) are good, while \(\texttt{11}\), \(\texttt{101}\), \(\texttt{001}\), \(\texttt{001100}\) are not good.

Qingshan wants to make \(s\) good. To do this, she can do the following operation at most \(300\) times (possibly, zero):

  • insert \(\texttt{01}\) to any position of \(s\) (getting a new \(s\)).

Please tell Qingshan if it is possible to make \(s\) good. If it is possible, print a sequence of operations that makes \(s\) good.
Input

The input consists of multiple test cases. The first line contains a single integer \(t\) (\(1\le t\le 100\)) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer \(n\) (\(1 \le n\le 100\)) — the length of string \(s\), respectively.

The second line of each test case contains a string \(s\) with length \(n\).

It is guaranteed that \(s\) only consists of \(\texttt{0}\) and \(\texttt{1}\).


B 1300

Tema decided to improve his ice cream making skills. He has already learned how to make ice cream in a cone using exactly two balls.

Before his ice cream obsession, Tema was interested in mathematics. Therefore, he is curious about the minimum number of balls he needs to have in order to make exactly \(n\) different types of ice cream.

There are plenty possible ice cream flavours: \(1, 2, 3, \dots\). Tema can make two-balls ice cream with any flavours (probably the same).

Two ice creams are considered different if their sets of ball flavours are different. For example, \(\{1, 2\} = \{2, 1\}\), but \(\{1, 1\} \neq \{1, 2\}\).

For example, having the following ice cream balls: \(\{1, 1, 2\}\), Tema can make only two types of ice cream: \(\{1, 1\}\) and \(\{1, 2\}\).

Note, that Tema do not need to make all the ice cream cones at the same time. This means that he making ice cream cones independently. Also in order to make a following cone \(\{x, x\}\) for some \(x\), Tema needs at least \(2\) balls of type \(x\).

Help Tema answer this question. It can be shown that answer always exist.
Input

Each test consists of multiple test cases. The first line of input contains a single integer \(t\) (\(1 \le t \le 10^4\)) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains a single integer \(n\) (\(1 \le n \le 10^{18}\)) — the number of ice cream types that Tema wants to make.


------------------------思考------------------------

  • 字符串/贪心策略+思维/贪心策略/二分/数学


A

  1. 首先保证 \(0/1\) 数量相等,一个方向是不动原字符串/对称轴不变,构造出一个一对一的字符串,但是做不到。
  2. 只能在两边加串,贪心消除即可,操作次数至多 \(n\) 次。暴力拼接更新字符串即可,注意点就是 \(sub\) 下标要细节一下。本质是将首尾字符进行移动。

B

  1. 是道好题。二分找出上界,剩余部分贪心,思想上证明一下。

------------------------代码------------------------

A

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST)                     \
    for (int i = ST; i < VEC.size(); i++) \
        cout << VEC[i] << ' ';            \
    el;

void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt[2] = {};
    for (auto v : s)
        cnt[v - '0']++;
    if (cnt[0] - cnt[1])
    {
        cout << -1;
        el;
        return;
    }
    int l = 0, r = n - 1;
    vector<int> res;
    // int t = 1e3;
    while (l < r)
    {
        // t--;
        // if (!t)
        //     break;
        if (s[l] - s[r])
        {
            l++, r--;
            continue;
        }
        if (s[l] == '1')
        {
            res.push_back(l);
            s = s.substr(0, l) + "01" + s.substr(l);
        }
        else
        {
            res.push_back(r + 1);
            // bug2(s.substr(0, r + 1), s.substr(r + 1));
            s = s.substr(0, r + 1) + "01" + s.substr(r + 1);
        }
        l++, r++;
        // bug2(l, r);
    }
    cout << res.size();
    el;
    bugv(res, 0);
}

B

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST)                         \
    {                                         \
        for (int I = ST; I < VEC.size(); I++) \
            cout << VEC[I] << ' ';            \
        el;                                   \
    }

void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n;
    cin >> n;
    int l = 1, r = 1e10;
    while (r - l - 1)
    {
        int mid = l + r >> 1;
        if (mid * (mid - 1) >> 1 > n)
            r = mid;
        else
            l = mid;
    }
    int res = l;
    res += n - (l * (l - 1) >> 1);
    cout << res << endl;
}

// void _()
// {
//     auto cal = [](int mid)
//     {
//         return mid * (mid - 1) >> 1;
//     };
//     for (int i = 2; i <= 20; i++)
//         bug2(i, cal(i));
// }

标签:2025.1,21,int,make,texttt,ice,test,1300,cream
From: https://www.cnblogs.com/jkkk/p/18685340

相关文章

  • 25/1/21 模拟赛做题记录
    最不会的一集。B题意Alice喜欢旅游,在这个假期里他将沿着公路骑行。可供Alice选择的道路构成了一张连通无向图,Alice的起点位于\(1\)号点,终点位于\(n\)号点,每条道路有一个困难度\(v_i\)。定义一条路径的疲劳度为他路上经过的所有道路的困难度的最大值。一开始Alice......
  • 2025/1/21学习
    #include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=1e5+10;intMax,Min,n,t;inta[N],b[N];boolcheck(intx){intlim=Max-x;intL=-1,R;for(inti=1;i<=n;++i){b[i]=a[i];if(a[i]<li......
  • 日常训练2025-1-21
    日常训练2025-1-21E双生双宿之错rating:1300https://ac.nowcoder.com/acm/contest/95323/E思路(数论)本题考查中位数定理,中位数有这样的性质:所有数与中位数的绝对差之和最小。中位数是数列中间的那个数,或者是中间的那两个数之一。所以最后得到的双生数组中的两种数即为数列......
  • 2025 年 IPTV/APTV 直播源m3u(1月21日更新)
    前言注意:仅供学术学习研究使用。⚠️长期更新,建议收藏!更新日志源不在多,而在于精。0930将直播源做了较大更新,删除了大量不可用源地址。1月21日新增IPTV源:https://iptv.hacks.tools/1月21日新增直播源网站1月1日更新确认源可用性。1016新......
  • 1.21
    1P1162填涂颜色-洛谷|计算机科学教育新生态(luogu.com.cn)只需要环最外圈的0,然后标记,最后填色时没有标记的标为2即可importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.io.Outp......
  • 1.21 JUnit单元测试
    JUnit单元测试1)在pom.xml中,引入JUnit的依赖点击查看代码<dependencies><!--https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api--><dependency><groupId>org.junit.jupiter</groupId><artifactId&......
  • 1.21练习
    原题地址https://www.luogu.com.cn/problem/P4552这道题是一道差分的题目,刚开始的时候我想的是找数列中的众数,然后求大于众数的数和小于众数的数与众数的最大差,然后再将它们相加,但这样很显然不对。在看了题解的思路后发现这道题其实不难(我太笨了)。首先这道题是说通过选定区间[l,......
  • 1.21
    二分图判定染色法二分图匹配匈牙利算法增广路(augmentingpath)是始于非匹配点且终于非匹配点(除了起始的点)的交错路。增广路中边的数量是奇数。增广路中,原匹配边变为非匹配边,可得到更大匹配枚举每个左部点,遍历所有边:1、若有未匹配的右部点,则将此两点匹配。2、否则递归处理......
  • [2025.1.20 JavaSE学习]类加载
    类加载基本说明反射机制是Java实现动态语言的关键,也就是通过反射实现类动态加载静态加载:编译时加载相关的类,如果没有则报错,依赖性太强动态加载:运行时加载需要的类,如果运行时不用该类,则不报错,降低了依赖性静态加载例子:Scannerscanner=newScanner(System.in);Stringke......
  • 2025.1.20——一、[RCTF2015]EasySQL1 二次注入|报错注入|代码审计
    题目来源:buuctf [RCTF2015]EasySQL1目录一、打开靶机,整理信息二、解题思路step1:初步思路为二次注入,在页面进行操作step2:尝试二次注入step3:已知双引号类型的字符型注入,构造payloadstep4:报错注入step5:三爆方法①extractvalue()函数方法②updatexml()函数三、小......