Code(2.5)

mmm is learning division, she's so proud of herself that she can figure out the sum of all the divisors (约数)of numbers no larger than 100 within one day! 
But her teacher said "What if I ask you to give not only the sum but the square-sums(平方和) of all the divisors of numbers within hexadecimal(十六进制) number 100?" mmm get stuck and she's asking for your help. 
Attention, because mmm has misunderstood teacher's words, you have to solve a problem that is a little bit different. 
Here's the problem, given n, you are to calculate the square sums of the digits of all the divisors of n, under the base m. 
InputMultiple test cases, each test cases is one line with two integers. 
n and m.(n, m would be given in 10-based) 
1≤n≤10 9 
2≤m≤16 
There are less then 10 test cases. 
OutputOutput the answer base m.Sample Input
10 2
30 5
Sample Output
110
112

        
  

Hint

Use A, B, C...... for 10, 11, 12......
Test case 1: divisors are 1, 2, 5, 10 which means 1, 10, 101, 1010 under base 2, the square sum of digits is 
1^2+ (1^2 + 0^2) + (1^2 + 0^2 + 1^2) + .... = 6 = 110
#include <iostream>
using namespace std;
char x[20]="0123456789ABCDEFG";//进制转换模板
int n,m;
int f(int x)
{
int  a[33],i=0;
while(x)
{
    a[i++]=x%m;
    x/=m;
}
int ans=0;
while(i--)
    ans+=a[i]*a[i];
    return ans;
}
int solve ()
{
    int i,ans=0;
    for(i=1;i*i<=n;i++)
        if(n%i==0)
    {
        ans+=f(i);
        if(i*i!=n)ans+=f(n/i);
    }
    return ans;
}
int main()
{
    while(cin>>n>>m){
        int a[33],i=0,ans=solve();
    while(ans){
        a[i++]=ans%m;
        ans/=m;
    }
    while(i--)
        cout<<x[a[i]];
    cout<<endl;
    }
        return 0;
} 



Alice and Bob are the topmost hunters in the forest,(森林中最强的猎手) so no preys can escape from them. However, they both think that its hunting skill is better than the other. So they need a match. In their match, the targets are two animals, a tiger and a wolf. They both know that the tiger is living in the south of the forest and the wolf is living in the north of the forest. They decide that the one who kills the tiger scores X points and who kills the wolf scores Y points. If the one who kills both tiger and wolf scores X+Y points. Before the match starts, Alice is in the east of the forest and Bob is in the west of the forest. When the match starts, Alice and Bob will choose one of the preys as targets. Because they haven't known the other's choice, maybe they choose the same target. There will be two situations: (1) If they choose different targets, they both are sure of killing their respective targets. (2) If they choose the same target, the probability of Alice killing the target is P, and the probability of Bob killing it is 1-P. Then they will hunt for the other prey, also the probability of Alice killing it is P and the probability of Bob killing it is 1-P. But Alice knows about Bob. She knows that the probability of Bob choosing tiger as his first target is Q, and the probability of choosing wolf is 1-Q. So that Alice can decide her first target to make her expected score as high as possible. 
InputThe first line of input contains an integer T (1≤T≤10000), the number of test cases. Then T test cases follow. Each test case contains X, Y, P, Q in one line. X and Y are integers and 1≤X, Y≤1000000000. P and Q are decimals and 0≤P, Q≤1, and there are at most two digits after decimal point. OutputFor each test case, output the target Alice should choose and the highest expected score she can get, in one line, separated by a space. The expected score should be rounded to the fourth digit after decimal point. It is guaranteed that Alice will have different expected score between choosing tiger and wolf.Sample Input
3
2 1 0.5 0.5
2 1 0 1
7 7 0.32 0.16
Sample Output
tiger 1.7500
wolf 1.0000
tiger 6.5968

#include <iostream>
using namespace std;
int main()
{
    int t,x,y;
    double p,q,d1,d2;
    cin>>t;
    while(t--)
    {
        cin>>x>>y>>p>>q;
//x是指的狼y指的老虎        
d1=(1-q)*x+p*q*(x+y);(bob选择狼那么Alice选择虎获得100%x加上 bob也选择虎然后他俩在一起选择狼运算式就是x+y*q*p)
        d2=(1-q)*p*(x+y)+q*y;(都先选择狼,再加上一虎一狼)
        if(d1>d2)
            printf("tiger %.4lf\n",d1);
        else
            printf("wolf %.4lf\n",d2);
    }
    return 0;
}(题目想知道Alice是应该选择虎还是 选择狼)

Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.

A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 20002004, but years 1900 and 2018 are not leap.

In this problem you are given n (1 ≤ n ≤ 24) integers a1, a2, ..., an, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a1 days, duration of the next month is a2 days, and so on.

Input

The first line contains single integer n (1 ≤ n ≤ 24) — the number of integers.

The second line contains n integers a1, a2, ..., an (28 ≤ ai ≤ 31) — the numbers you are to check.

Output

If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

You can print each letter in arbitrary case (small or large).

Example
Input
4
31 31 30 31
Output
Yes

Input
2
30 30
Output
No

Input
5
29 31 30 31 30
Output
Yes

Input
3
31 28 30
Output
No

Input
3
31 31 28
Output
Yes

Note

In the first example the integers can denote months July, August, September and October.

In the second example the answer is no, because there are no two consecutive months each having 30 days.

In the third example the months are: February (leap year) — March — April – May — June.

In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.

In the fifth example the months are: December — January — February (non-leap year).


#include <iostream>
#include <stdio.h>
using namespace std;
int n ,a[3],m[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
//前面补0为了让月份与数组下标对应。
int aim[33];
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>aim[i];
        //aim数组用来存储输入的月份天数
    int flag=0;
    int f=0;//两个标记
    for(int i=1; i<=12; i++)
    {
        //因为输入的月份不知道是从几月开始,那么就得从十二个月进行遍历。
        int len=1;//因为输入的月份是连续的所以从一开始进行累加遍历 。进行连续遍历到n为止。
        while(len<=n)
        {
            int to=i+len-1;//to是用来存储
            while(to>=13) to-=12;//如果超过了13进行换年份的调整
            if(to==2)
            {
                if(aim[len]==29&&f==0)
                {
                    f=1;
                    len++;
                    continue;
                }
                if(aim[len]==28)
                {
                    len++;
                    continue;
                }
                //这一步关键是防止连续两年是29 
                //加了这个特殊判定就能保证不会两年闰年的情况
            }
            if(aim[len]==m[to])
            {
                len++;
                continue;
            }
            break;
        }
        if(len==n+1)
        {
            flag=1;
            break;
        }
    }
    if(flag) printf("YES\n");
    else printf("NO\n");
    return 0 ;
}



一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市。 
Input
前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每行有1个数m,m<=20,m>=1.m=0退出. 
Output
输出从第m个城市出发经过每个城市1次又回到m的所有路线,如有多条路线,按字典序输出,每行1条路线.每行首先输出是第几条路线.然后个一个: 后列出经过的城市.参看Sample output 
Sample Input
2 5 20
1 3 12
2 4 10
3 5 8
1 4 6
5 7 19
6 8 17
4 7 9
8 10 16
3 9 11
10 12 15
2 11 13
12 14 20
13 15 18
11 14 16
9 15 17
7 16 18
14 17 19
6 18 20
1 13 19
5
0
Sample Output
1:  5 1 2 3 4 8 7 17 18 14 15 16 9 10 11 12 13 20 19 6 5
2:  5 1 2 3 4 8 9 10 11 12 13 20 19 18 14 15 16 17 7 6 5
3:  5 1 2 3 10 9 16 17 18 14 15 11 12 13 20 19 6 7 8 4 5
4:  5 1 2 3 10 11 12 13 20 19 6 7 17 18 14 15 16 9 8 4 5
5:  5 1 2 12 11 10 3 4 8 9 16 15 14 13 20 19 18 17 7 6 5
6:  5 1 2 12 11 15 14 13 20 19 18 17 16 9 10 3 4 8 7 6 5
7:  5 1 2 12 11 15 16 9 10 3 4 8 7 17 18 14 13 20 19 6 5
8:  5 1 2 12 11 15 16 17 18 14 13 20 19 6 7 8 9 10 3 4 5
9:  5 1 2 12 13 20 19 6 7 8 9 16 17 18 14 15 11 10 3 4 5
10:  5 1 2 12 13 20 19 18 14 15 11 10 3 4 8 9 16 17 7 6 5
11:  5 1 20 13 12 2 3 4 8 7 17 16 9 10 11 15 14 18 19 6 5
12:  5 1 20 13 12 2 3 10 11 15 14 18 19 6 7 17 16 9 8 4 5
13:  5 1 20 13 14 15 11 12 2 3 10 9 16 17 18 19 6 7 8 4 5
14:  5 1 20 13 14 15 16 9 10 11 12 2 3 4 8 7 17 18 19 6 5
15:  5 1 20 13 14 15 16 17 18 19 6 7 8 9 10 11 12 2 3 4 5
16:  5 1 20 13 14 18 19 6 7 17 16 15 11 12 2 3 10 9 8 4 5
17:  5 1 20 19 6 7 8 9 10 11 15 16 17 18 14 13 12 2 3 4 5
18:  5 1 20 19 6 7 17 18 14 13 12 2 3 10 11 15 16 9 8 4 5
19:  5 1 20 19 18 14 13 12 2 3 4 8 9 10 11 15 16 17 7 6 5
20:  5 1 20 19 18 17 16 9 10 11 15 14 13 12 2 3 4 8 7 6 5
21:  5 4 3 2 1 20 13 12 11 10 9 8 7 17 16 15 14 18 19 6 5
22:  5 4 3 2 1 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5
23:  5 4 3 2 12 11 10 9 8 7 6 19 18 17 16 15 14 13 20 1 5
24:  5 4 3 2 12 13 14 18 17 16 15 11 10 9 8 7 6 19 20 1 5
25:  5 4 3 10 9 8 7 6 19 20 13 14 18 17 16 15 11 12 2 1 5
26:  5 4 3 10 9 8 7 17 16 15 11 12 2 1 20 13 14 18 19 6 5
27:  5 4 3 10 11 12 2 1 20 13 14 15 16 9 8 7 17 18 19 6 5
28:  5 4 3 10 11 15 14 13 12 2 1 20 19 18 17 16 9 8 7 6 5
29:  5 4 3 10 11 15 14 18 17 16 9 8 7 6 19 20 13 12 2 1 5
30:  5 4 3 10 11 15 16 9 8 7 17 18 14 13 12 2 1 20 19 6 5
31:  5 4 8 7 6 19 18 17 16 9 10 3 2 12 11 15 14 13 20 1 5
32:  5 4 8 7 6 19 20 13 12 11 15 14 18 17 16 9 10 3 2 1 5
33:  5 4 8 7 17 16 9 10 3 2 1 20 13 12 11 15 14 18 19 6 5
34:  5 4 8 7 17 18 14 13 12 11 15 16 9 10 3 2 1 20 19 6 5
35:  5 4 8 9 10 3 2 1 20 19 18 14 13 12 11 15 16 17 7 6 5
36:  5 4 8 9 10 3 2 12 11 15 16 17 7 6 19 18 14 13 20 1 5
37:  5 4 8 9 16 15 11 10 3 2 12 13 14 18 17 7 6 19 20 1 5
38:  5 4 8 9 16 15 14 13 12 11 10 3 2 1 20 19 18 17 7 6 5
39:  5 4 8 9 16 15 14 18 17 7 6 19 20 13 12 11 10 3 2 1 5
40:  5 4 8 9 16 17 7 6 19 18 14 15 11 10 3 2 12 13 20 1 5
41:  5 6 7 8 4 3 2 12 13 14 15 11 10 9 16 17 18 19 20 1 5
42:  5 6 7 8 4 3 10 9 16 17 18 19 20 13 14 15 11 12 2 1 5
43:  5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5
44:  5 6 7 8 9 16 17 18 19 20 1 2 12 13 14 15 11 10 3 4 5
45:  5 6 7 17 16 9 8 4 3 10 11 15 14 18 19 20 13 12 2 1 5
46:  5 6 7 17 16 15 11 10 9 8 4 3 2 12 13 14 18 19 20 1 5
47:  5 6 7 17 16 15 11 12 13 14 18 19 20 1 2 3 10 9 8 4 5
48:  5 6 7 17 16 15 14 18 19 20 13 12 11 10 9 8 4 3 2 1 5
49:  5 6 7 17 18 19 20 1 2 3 10 11 12 13 14 15 16 9 8 4 5
50:  5 6 7 17 18 19 20 13 14 15 16 9 8 4 3 10 11 12 2 1 5
51:  5 6 19 18 14 13 20 1 2 12 11 15 16 17 7 8 9 10 3 4 5
52:  5 6 19 18 14 15 11 10 9 16 17 7 8 4 3 2 12 13 20 1 5
53:  5 6 19 18 14 15 11 12 13 20 1 2 3 10 9 16 17 7 8 4 5
54:  5 6 19 18 14 15 16 17 7 8 9 10 11 12 13 20 1 2 3 4 5
55:  5 6 19 18 17 7 8 4 3 2 12 11 10 9 16 15 14 13 20 1 5
56:  5 6 19 18 17 7 8 9 16 15 14 13 20 1 2 12 11 10 3 4 5
57:  5 6 19 20 1 2 3 10 9 16 15 11 12 13 14 18 17 7 8 4 5
58:  5 6 19 20 1 2 12 13 14 18 17 7 8 9 16 15 11 10 3 4 5
59:  5 6 19 20 13 12 11 10 9 16 15 14 18 17 7 8 4 3 2 1 5
60:  5 6 19 20 13 14 18 17 7 8 4 3 10 9 16 15 11 12 2 1 5
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int Path[22];
int Map[22][3];
int vis[22];
int T;
int m;


void dfs(int num, int step)
{
    if(num == m && step != 0 && step < 20)
        return;
    if(num == m && step == 20)
    {
        printf("%d:  %d", T ++, m);


        for(int i = 0; i < 20; i ++)
            printf(" %d", Path[i]);


        puts("");
    }
    for(int i = 0; i < 3; i ++)
        if(!vis[Map[num][i]])
        {
            vis[Map[num][i]] = true;
            Path[step] = Map[num][i];
            dfs(Map[num][i], step + 1);
            vis[Map[num][i]] = false;
        }
}


int main(void)
{
    for(int i = 1; i <= 20; i ++)
        cin >> Map[i][0] >> Map[i][1] >> Map[i][2];
    while(scanf("%d", &m) == 1)
    {
        memset(vis, 0, sizeof(vis));
        T = 1;
        dfs(m, 0);
    }
    return 0;
}

内容概要:本文深入探讨了Kotlin语言在函数式编程和跨平台开发方面的特性和优势,结合详细的代码案例,展示了Kotlin的核心技巧和应用场景。文章首先介绍了高阶函数和Lambda表达式的使用,解释了它们如何简化集合操作和回调函数处理。接着,详细讲解了Kotlin Multiplatform(KMP)的实现方式,包括共享模块的创建和平台特定模块的配置,展示了如何通过共享业务逻辑代码提高开发效率。最后,文章总结了Kotlin在Android开发、跨平台移动开发、后端开发和Web开发中的应用场景,并展望了其未来发展趋势,指出Kotlin将继续在函数式编程和跨平台开发领域不断完善和发展。; 适合人群:对函数式编程和跨平台开发感兴趣的开发者,尤其是有一定编程基础的Kotlin初学者和中级开发者。; 使用场景及目标:①理解Kotlin中高阶函数和Lambda表达式的使用方法及其在实际开发中的应用场景;②掌握Kotlin Multiplatform的实现方式,能够在多个平台上共享业务逻辑代码,提高开发效率;③了解Kotlin在不同开发领域的应用场景,为选择合适的技术栈提供参考。; 其他说明:本文不仅提供了理论知识,还结合了大量代码案例,帮助读者更好地理解和实践Kotlin的函数式编程特性和跨平台开发能力。建议读者在学习过程中动手实践代码案例,以加深理解和掌握。
内容概要:本文深入探讨了利用历史速度命令(HVC)增强仿射编队机动控制性能的方法。论文提出了HVC在仿射编队控制中的潜在价值,通过全面评估HVC对系统的影响,提出了易于测试的稳定性条件,并给出了延迟参数与跟踪误差关系的显式不等式。研究为两轮差动机器人(TWDRs)群提供了系统的协调编队机动控制方案,并通过9台TWDRs的仿真和实验验证了稳定性和综合性能改进。此外,文中还提供了详细的Python代码实现,涵盖仿射编队控制类、HVC增强、稳定性条件检查以及仿真实验。代码不仅实现了论文的核心思想,还扩展了邻居历史信息利用、动态拓扑优化和自适应控制等性能提升策略,更全面地反映了群体智能协作和性能优化思想。 适用人群:具备一定编程基础,对群体智能、机器人编队控制、时滞系统稳定性分析感兴趣的科研人员和工程师。 使用场景及目标:①理解HVC在仿射编队控制中的应用及其对系统性能的提升;②掌握仿射编队控制的具体实现方法,包括控制器设计、稳定性分析和仿真实验;③学习如何通过引入历史信息(如HVC)来优化群体智能系统的性能;④探索中性型时滞系统的稳定性条件及其在实际系统中的应用。 其他说明:此资源不仅提供了理论分析,还包括完整的Python代码实现,帮助读者从理论到实践全面掌握仿射编队控制技术。代码结构清晰,涵盖了从初始化配置、控制律设计到性能评估的各个环节,并提供了丰富的可视化工具,便于理解和分析系统性能。通过阅读和实践,读者可以深入了解HVC增强仿射编队控制的工作原理及其实际应用效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值