22.02.17

今天比较忙,没什么状态做题

只做了一些练练手感

最小字符串

问题描述
  给定一些字符串(只包含小写字母),要求将他们串起来构成一个字典序最小的字符串。
输入格式
  第一行T,表示有T组数据。
  接下来T组数据
  每组第一行一个正整数n,表示字符串个数。
  接下来n行,每行一个字符串(长度不超过100)。
输出格式
  T行,每行一个字符串。

样例输入

1
3
a
b
c


样例输出
abc
数据规模和约定
  T<=7000,n<=100;

这样例给了还不如不给

一眼看去还以为是对字符串排序后加起来(

然后一个都没对

看了样例发现相距甚远

发现b ,ba这两个数据b在前面而+起来bba>bab

然后又尝试贪心

用双指针last 和pre保存目前总结果和新加进来的字符串

那个小用哪种

#include<iostream>
#include<string>
#include<cctype>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
using namespace std;

int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        string temp;
        int t;
        cin>>t;
        string sum="";

        string pre;
        string last;
        cin>>pre;
        while(--t)
        {

            cin>>last;
            if(pre+last>last+pre)
            {
                last=last+pre;
            }
            else
            {
                last=pre+last;
            }
            pre=last;
        }
        for(int i=0;i<pre.length();i++)
        {
            cout<<pre[i];
        }
        cout<<endl;
        getchar();
    }
    return 0;
}

当然还是想错了,我也觉得很奇怪,应该没什么问题才对

然后借鉴了一下大佬的博客

发现居然是我排序错了

要按照一个奇奇怪怪的cmp法则排序

个人理解为按照两个字符串相加那种在前排序小就放在前面

bool cmp(string a, string b)
{
    string t1=a+b,t2=b+a;
    if(t1 < t2)
        return true;
    else
        return false;
}

个人感觉写成a+b<b+a就好了,还容易理解

实际上也确实可以

#include<iostream>
#include<string>
#include<cctype>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
using namespace std;

bool cmp(string a, string b)
{
    return a+b<b+a;
}

int main()
{
    std::ios::sync_with_stdio(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        string sum="";
        string temp[n];
        for(int i = 0; i < n; i++)
            cin >> temp[i];
        sort(temp,temp+n,cmp);

        for(int i = 0; i < n; i++)
            sum += temp[i];
        cout << sum << endl;
    }
    return 0;
}

用PYTHON编写自1971年7月开始,道琼斯工业股票平均价格指数每周收盘价如表所示(行数据)。 890.19 901.8 888.51 887.78 858.43 850.61 856.02 880.91 908.15 912.75 911 908.22 889.31 893.98 893.91 874.85 852.37 839 840.39 812.94 810.67 816.55 859.59 856.75 873.8 881.17 890.2 910.37 906.68 907.44 906.38 906.68 917.59 917.52 22.79 942.43 939.87 942.88 942.28 940.7 962.6 967.72 963.8 954.17 941.23 941.83 961.54 971.25 961.39 934.45 945.06 944.69 929.03 938.06 922.26 920.45 926.7 951.76 964.18 965.83 959.36 970.05 961.24 947.23 943.03 953.27 945.36 930.46 942.81 946.42 984.12 995.26 1005.57 1025.21 1023.43 1033.19 1027.24 1004.21 1020.02 1047.49 1039.36 1026.19 1003.54 980.81 979.46 979.23 959.89 961.32 972.23 963.05 922.71 951.01 931.07 959.36 963.2 922.19 953.87 927.89 895.17 930.84 893.96 920 888.55 879.82 891.71 870.11 885.99 910.9 936.71 908.87 852.38 871.84 863.49 887.57 898.63 886.36 927.9 947.1 971.25 978.63 963.73 987.06 935.28 908.42 891.33 854 822.25 838.05 815.65 818.73 848.02 880.23 841.48 855.47 859.39 843.94 820.4 820.32 855.99 851.92 878.05 887.83 878.13 846.68 847.54 844.81 859.9 834.64 845.9 850.44 818.84 816.65 802.17 853.72 843.09 815.39 802.41 791.77 787.23 787.94 784.57 752.58(1)检验该序列的平稳性。 (2)对该序列拟合适当的ARIMA模型提取水平信息。 (3)考察该序列是否具有条件异方差属性。如果有条件异方差属性,则拟合适当的条件异方差模型。 (4)使用拟合模型预测该序列未来4周的收盘价及收盘价的95%的置信区间。
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值