任务三

Posted lusiqi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了任务三相关的知识,希望对你有一定的参考价值。

B - Everyone is a Winner!

On the well-known testing system MathForces, a draw of n rating units is arranged. The rating will be distributed according to the following algorithm: if k participants take part in this event, then the n rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants.

For example, if n=5 and k=3, then each participant will recieve an 1 rating unit, and also 2 rating units will remain unused. If n=5, and k=6, then none of the participants will increase their rating.

Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help.

For example, if n=5, then the answer is equal to the sequence 0,1,2,5. Each of the sequence values (and only them) can be obtained as ⌊n/k⌋ for some positive integer k (where ⌊x⌋ is the value of x rounded down): 0=⌊5/7⌋, 1=⌊5/5⌋, 2=⌊5/2⌋, 5=⌊5/1⌋.

Write a program that, for a given n, finds a sequence of all possible rating increments.

Input

The first line contains integer number t (1≤t≤10) — the number of test cases in the input. Then t test cases follow.

Each line contains an integer n (1≤n≤109) — the total number of the rating units being drawn.

Output

Output the answers for each of t test cases. Each answer should be contained in two lines.

In the first line print a single integer m — the number of different rating increment values that Vasya can get.

In the following line print m integers in ascending order — the values of possible rating increments.

Sample Input

4
5
11
1
3

Sample Output

4
0 1 2 5
6
0 1 2 3 5 11
2
0 1
3
0 1 3

题意:

一共有n块钱,k个人[n/k]块钱,向下取整。

现在给你n块钱,你不知道有多少人,输出每个人可能获得多少钱

求数字N它被除后的数
 
 
set中的元素都是排好序的
set集合中没有重复的元素
set容器内所有元素都是以节点的方式来存储,其节点结构和链表差不多,指向父节点和子节点
因此插入的时候只需稍作变换,把节点的指针指向新的节点就可以了,删除类似
这里的一切操作都是指针的变换,和内存移动是没有关系的
 在set中查找是使用二分查找
代码:
#include<iostream>
#include<stdio.h>
#include<set>
using namespace std;
int main(){
    int  t;
    cin>>t;
    for(int i=1;i<=t;i++){
        int n;
        cin>>n;
        set<int> s; 
        for(int i=1;i*i<=n;i++){
            s.insert(i);
            s.insert(n/i);
        }
        cout<<s.size()+1<<endl;
        s.insert(0);
        for(auto x:s){
            cout<<x<<" ";
        } 
        cout<<endl;
    } 

} 

 

E - PIN Codes

output

standard output

A PIN code is a string that consists of exactly 44 digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0.

Polycarp has nn (2≤n≤102≤n≤10) bank cards, the PIN code of the ii-th card is pipi.

Polycarp has recently read a recommendation that it is better to set different PIN codes on different cards. Thus he wants to change the minimal number of digits in the PIN codes of his cards so that all nn codes would become different.

Formally, in one step, Polycarp picks ii-th card (1≤i≤n1≤i≤n), then in its PIN code pipi selects one position (from 11 to 44), and changes the digit in this position to any other. He needs to change the minimum number of digits so that all PIN codes become different.

Polycarp quickly solved this problem. Can you solve it?

Input

The first line contains integer tt (1≤t≤1001≤t≤100) — the number of test cases in the input. Then test cases follow.

The first line of each of tt test sets contains a single integer nn (2≤n≤102≤n≤10) — the number of Polycarp‘s bank cards. The next nn lines contain the PIN codes p1,p2,…,pnp1,p2,…,pn — one per line. The length of each of them is 44. All PIN codes consist of digits only.

Output

Print the answers to tt test sets. The answer to each set should consist of a n+1n+1 lines

In the first line print kk — the least number of changes to make all PIN codes different. In the next nn lines output the changed PIN codes in the order corresponding to their appearance in the input. If there are several optimal answers, print any of them.

Example

input

Copy

3
2
1234
0600
2
1337
1337
4
3139
3139
3139
3139

output

Copy

0
1234
0600
1
1337
1237
3
3139
3138
3939
6139

 
题意:
把n个数通过改变,使这N个数字都不相同,并且每次改变其中一个数中的一位数
求最小的改变次数
改变后的数输出任意组就行
 
 
map是STL的一个关联容器,它提供一对一的hash
第一个可以称为关键字,每个关键字只能在map中出现一次
第二个可能称为该关键字的值
map以模板方式实现,可以存储任意类型的数据,包括使用者自定义的数据类型。Map主要用于
一对一映射的情况,map内部的实现自建一颗红黑树,这棵树具有对数据自动排序的功能,在map4
内部所有的数据都是有序,后面我们会见识到有序的好处,
map对象是模板类,需要关键字和存储对象两个模板参数
 
代码:
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
int h[15];
int main(){
    int t;
    cin>>t;
    
    for(int i=1;i<=t;i++){
        int ans = 0;
        int n;
        cin>>n;
        map<int,int>A;
        map<int,int>B;
        for(int i=1;i<=n;i++){
            scanf("%d",&h[i]);
            A[h[i]]++;
            B[h[i]%10]++;
            if(A[h[i]]>=2){
                ans++;
            } 
        }
        cout<<ans<<endl;
        
        for(int i = 1;i<=n;i++){
            if(A[h[i]]>=2){
                A[h[i]]--;
                int g = h[i];
                int m1 = g%10; g = g/10;
                int m2 = g%10; g = g/10;
                int m3 = g%10; g=g/10;
                int m4 = g;
                for(int j = 0;j<=9;j++){
                    if(B[j]==0){
                        B[j]++;
                        cout<<m4<<m3<<m2<<j<<endl;
                        break;
                    }
                } 
            }
            else{
                printf("%04d
",h[i]);//保证当第一位为0的情况 
            }
        
        }     
    }
}

 

 

C - Sweet Problem

You have three piles of candies: red, green and blue candies:

the first pile contains only red candies and there are rr candies in it,
the second pile contains only green candies and there are gg candies in it,
the third pile contains only blue candies and there are bb candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can’t eat two candies of the same color in a day.

Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.

Input

The first line contains integer tt (1≤t≤10001≤t≤1000) — the number of test cases in the input. Then tt test cases follow.

Each test case is given as a separate line of the input. It contains three integers rr, gg and bb (1≤r,g,b≤1081≤r,g,b≤108) — the number of red, green and blue candies, respectively.

Output

Print tt integers: the ii-th printed integer is the answer on the ii-th test case in the input.

Example

input

Copy

6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
output

Copy

1
2
2
10
5
9
Note

In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.

In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.

In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.

题意:

有 r 个红糖果,g 个绿糖果,b 个蓝糖果,1 <= r,g,b <= 10^8. 每天只能吃两个糖果,问最多可以吃多少天。

思路:

先找出数量最多的哪一种糖果,如果那种糖果的数量大于另外两种糖果的数量之和,则答案必然是另外两种的糖果的数量和,因为即使是每天都吃数量最多的糖果,最后也必然会只剩下哪一种糖果。
如果数量最多的糖果的数量小于等于另外两种糖果数量之和,则输出三者的数量和除以2的结果(小数则向下取整)。因为对于任意满足条件的三个数a,b,c(降序),可以先使a与b配对,剩下的与c配对,最后必然会有c剩下,然后不断拆掉a,b的一对,至c<=1;若a+b+c为奇数,则必然剩下一颗,为偶数则必然全部吃完。

代码:

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
    ll t,a[3];
    scanf("%lld",&t);
    while(t--){
        scanf("%lld%lld%lld",&a[0],&a[1],&a[2]);
        sort(a,a+3);
        if(a[2]>a[0]+a[1])
            printf("%lld
",a[1]+a[0]);
        else
            printf("%lld
",(a[0]+a[1]+a[2])/2);
    }
    return 0;
}

 

以上是关于任务三的主要内容,如果未能解决你的问题,请参考以下文章

C++项目三代码参考(改进版)

汇编实验九

汇编实验五

实验四

日常Geetest滑动验证码(三代canvas版)处理小结(以B站登录验证为例)

实验五