SDUT 2022 summer team contest 3rd(for 21)

前言:2nd倒五,3rd第五,正负相消,成绩稳定(bushi)

A - A Count Task

Count is one of WNJXYK’s favorite tasks. Recently, he had a very long string and he wondered that how many substrings which contains exactly one kind of lowercase in this long string. But this string is so long that he had kept counting for several days. His friend Kayaking wants to help him, so he turns to you for help.

Input

The input starts with one line contains exactly one positive integer TT which is the number of test cases.
Each test case contains one line with a string which you need to do a counting task on.

Output

For each test case, output one line containing “y” where y is the number of target substrings.

Sample

InputcopyOutputcopy
 
3 qwertyuiop qqwweerrttyyuuiioopp aaaaaaaaaa
 
10 30 55

Hint


1<=T<=20,1<=len(string)<=10^5,1<=∑len(string)<=10^5
Strings only contain lowercase English letters.

鲸鱼的作品,我还没来得及研究hh

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1010;

ll change(int sum)
{
  ll ans = 0;
  for (int i = 1; i <= sum; i++)
    ans += i;
  return ans;
}
int main()
{
  int n;
  cin >> n;
  string a;
  for (int k = 1; k <= n; k++)
  {
    cin >> a;
    int sum=0;
    int flag=0;
    ll ans = 0;
    for (int i = 0; i < a.size(); i++)
    {
      if (a[i] != a[flag])
      {
        ans += change(sum);
        sum=1;
       flag=i;
      }
      else
      sum++;
      
    }
    ans+=change(sum);
    cout << ans << endl;
  }

  return 0;
}

E - A Hard Allocation

One day, WNJXYK came out an excellent idea that he could give his friends his special cakes which made of kiwis to eat in parties. But the process of making this kind of special cakes is very complex. One day, his friend Kayaking gave him a formulation which allows WNJXYK to produce one special cake with exact one kiwi in no time. Now let us have a big party over anyone’s imagination.
To simply this question we can assume that WNJXYK invited m friends to his house and he only had n kiwis this time. He wanted to produce special cakes with Kayaking’s formulation and give them to his friends.
Usually, it maybe not possible for people to get exactly same number of cakes in some situations. We can assume that people who received the most one get x cakes and people who received the least get y cakes. WNJXYK wondered that what is the minimal value of |x-y|?

Input

The input starts with one line contains exactly one positive integer T which is the number of test cases.
Each test case contains one line with exactly two positive integer n,m which has been explained above.

Output

For each test case, output one line containing “y” where y is the number of minimal difference.

Sample

InputcopyOutputcopy
 
3 5 5 3 10 6 7
 
0 1 1

Hint


1<=T<=100,1<=n,m<=1000

只有0和1两种情况,看看能不能整除就ok,忽略我没及时更改的水印

/*Where there is light, in my heart.*/
/*SUMMER_TRAINING DAY 26*/
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
//
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define INF 0x3f3f3f
#define ll long long
#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define unmap(a,b) unordered_map<a,b>
#define unset(a) unordered_set<a>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define _rep(i, a, b) for (int i = (a); i >= (b); --i)
#define mode 1e4+7
#define pi acos(-1)
#define U_queue priority_queue<PII,vector<PII>,greater<PII> >
typedef double db;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> vi;
const int N = 1005;
signed main(){
     int t;
     int n,m;
     cin>>t;
     while(t--){
          cin>>n>>m;
          if(n%m==0) cout<<0<<endl;
          else cout<<1<<endl;
     }
}
//made by shun 20220729//

G - Flower

Rabbit loves flowers very much and she plants n pots of flowers in her house. But she never prunes them because she is lazy. So the flowers have different heights and look ugly. One day, Kayaking decides to prune the flowers to make them look beautiful. To make them have equal heights, smart Kayaking has a wonderful idea. Initially, the i-th pot of flower’s height is a[i]. Each time, Kayaking will select n-1 pots of flowers and prune them to make their height subtract 1 with his 49m knife. Exactly, the height of the flowers is at least 1. Now, Kayaking wants to know if it is possible to prune the flowers to make them have equal height. If possible, what is the minimum times he prunes the flowers. Could you tell him?

Input

The input starts with a line contains exactly one positive number T which is the number of test case.
  Each test case starts with a line contains a number n indicates the number of flowers. Then there is a line contains n numbers indicates a[i].

Output

For each test case, print a single line containing one integer―the minimum times Kayaking prunes the flowers, or -1 if it is impossible.

Sample

InputcopyOutputcopy
 
2 5 1 2 2 2 2 5 1 2 2 2 3
 
1 -1

Hint


T<=10,n<=10^5,ai<=10^9

原题是减n-1,我们可以逆向考虑为没减的楼相对于其他楼的高度加一,开一个sum来计对最高的操作次数如果最高减掉sum小于了1

那么就不可以 反之输出sum

/*Where there is light, in my heart.*/
/*SUMMER_TRAINING DAY 26*/
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
//
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define INF 0x3f3f3f
#define ll long long
#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define unmap(a,b) unordered_map<a,b>
#define unset(a) unordered_set<a>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define _rep(i, a, b) for (int i = (a); i >= (b); --i)
#define mode 1e4+7
#define pi acos(-1)
#define U_queue priority_queue<PII,vector<PII>,greater<PII> >
typedef double db;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> vi;
const int N = 1e5+5;
signed main(){
     IOS;
     int t;
     int n;
     ll a[N];
     cin>>t;
     while(t--){
          cin>>n;
          for(int i=0;i<n;i++){
               cin>>a[i];
               //b[i]++;
          }
          ll sum=0;
          sort(a,a+n);
          //if(b[a[n-1]]>1) cout<<-1<<endl;
          for(int i=0;i<n;i++){
               sum+=a[n-1]-a[i];
          }
          if(a[n-1]-sum<1) cout<<-1<<endl;
          else cout<<sum<<endl; 
     }
}
//made by shun 20220729

H - Overflow

Kayaking is a naughty boy and he loves to play water. One day, Kayaking finds a bucket. The bottom area of the bucket is S and the height is H. Initially, there is V volume water in the bucket. What makes Kayaking happy is that there are N cube woods beside the bucket. The side length of the i-th cube woods is L[i] and its density is P[i]. Kayaking wants to put all the cube woods to the bucket. And then he will put a cover at the top of the bucket. But CoffeeDog doesn’t allow unless Kayaking can tell CoffeeDog the height of the water in the bucket after Kayaking put all the cuboid woods to the bucket. Could you help him?
It is guaranteed that the cube woods aren’t overlapping. And after putting the wood to the bucket, the bottom of the wood is parallel to the bottom of the bucket.

Input

The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of cube woods.
Then comes N line. Each line has two real numbers L[i] and P[i].
The last line contains three integers S, H and V.

Output

For each test cases, print a single line containing one real number―the height of the water in the bucket(the number should be rounded to the second digit after the decimal point).

Sample

InputcopyOutputcopy
 
1 2 1 1.5 1 0.5 5 100 25
 
5.30

Hint


T<=10
n<=10^4,P<=6,L<=3,H<=100,L<=H
V,S<=10^7

队友写的,我没参与hh

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 10001000;
double s[N],d[N];
int main()
{
  int t;
  scanf("%d",&t);
  while(t--)
  {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
      scanf("%lf%lf",&s[i],&d[i]);
    }
    double S,H,V;

    scanf("%lf%lf%lf",&S,&H,&V);
    double ans=V/S;
    for(int i =1;i<=n;i++)
    {
      if(d[i]>=1)
      {
        /* if(s[i]>ans*S/(S-s[i]*s[i]))
        {
          ans=ans*S/(S-s[i]*s[i]);
          S-=s[i]*s[i];
        }
        else */
        ans+=s[i]*s[i]*s[i]/S;
      }
      
      else
      {
        ans+=d[i]*s[i]*s[i]*s[i]/S;
      }
    }
    if(ans>=H)
    printf("%.2lf\n",H);
    else
    printf("%.2lf\n",ans);
  }
  return 0;
}

J - The puzzle

Kayaking is playing a puzzle game containing n different blocks. He marks the blocks with integers from 1 to n, which show the blocks’ original positions. Each time he can exchange two blocks and he wants to know how many times he needs at least to restore the puzzle.

Input

The input starts with one line contains exactly one positive integer which is the number of test cases.
Each test case contains two lines.
The first line contains an integer, which indicates the number of puzzle pieces.
The second line contains n different integers, the i-th number means the mark of the block in the i-th position.

Output

For each test case, output one line with one number represents the minimum operations.

Sample

InputcopyOutputcopy
 
2 4 2 3 4 1 4 2 1 4 3
 
3 2

Hint


1<=T<=20,1<=n<=100000

因为是任意交换嘛,所以不用考虑太多,直接暴力就是最少的方法

记得比赛前都要检查一下自己的变量设置,因为这个t了一发

/*Where there is light, in my heart.*/
/*SUMMER_TRAINING DAY 26*/
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
//
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define INF 0x3f3f3f
#define ll long long
#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define unmap(a,b) unordered_map<a,b>
#define unset(a) unordered_set<a>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define _rep(i, a, b) for (int i = (a); i >= (b); --i)
#define mode 1e4+7
#define pi acos(-1)
#define U_queue priority_queue<PII,vector<PII>,greater<PII> >
typedef double db;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> vi;
const int N = 1e5+5;
signed main(){
     IOS;
     int t;
     int n;
     int a[N];
     cin>>t;
     while(t--){
          int ans=0;
          cin>>n;
          for(int i=1;i<=n;i++) cin>>a[i];
          for(int i=1;i<=n;){
               if(i==a[i]) i++;
               else if(i!=a[i]){
                    swap(a[i],a[a[i]]);
                    ans++;
               }
          }
          cout<<ans<<endl;     
     }
}
//made by shun 20220729//

总结:还有很多题没补,看看有价值的话再补充,这次的问题出在小细节的把控上,但是总体来说我们队这个周的末尾比赛还是打的不错的hhh

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值