13训练赛01

开学第一次训练赛,很失败,很苦逼,却毫不意外。毕竟暑假没能把大把时间花在ACM上,现在的结果实在意料之内。

A题,乍一眼看以为能做,仔细一看就知道自己想多了,五千万的五千万次方还要求约数和,光是随便一个约数都是高精度型做不来了的。。。

B题,看题,看Sample,没看懂,果断pass。。。

C题终于是看懂并且瞬间觉得能做的了。虽说什么稳定排序不稳定排序以前并不了解,不过不影响做题,现场看题学习下还是没出什么大问题就做了出来。

D题是花了最多时间的一道题。做之前就预测肯定TLE,但相比其他根本不可能做出来的题,我对这题要求只是样本能过,然而即使只要求这样仍然很是艰辛。首先题意就理解的不清楚,在几块石头处于同一位置的时候,一直没弄明白是怎么处理的,英语的渣水平让我以为是只选Di最小的处理。后来结合了Sample2才看明白是按照Di从小到大处理。然后最开始的时候一直想着给石头照Pi的值排序,这样的话每次第一块石头就是要处理的那块,不过我所知道的最简洁的排序只是sort,可惜sort该怎么对结构体排序一直没弄明白,这就纠结了好半天,最终决定不排序了,直接每轮都找出要处理的那块石头,结果这样一想发现本来就没有排序的必要。最后在选石头的事情上又弄错了好半天,不过这些主要就是因为不仔细了,最终结果,TLE,但样本,包括自己随便给的几组数据都过了,基本达到要求。

E题看完目测类似凸包问题,但具体怎么做还是不太熟练,只能放弃。

F题完全无思路,还没准备到这类问题。

G题疑似最优情况之类的东西,跳过。。

H、I题都没看,回宿舍后看了下,只能看懂题目而已。

总的来说,对这次训练赛还是有种下马威的感觉吧,不过确实自己暑假做的不够好,也就在接下来多花时间在这上面吧,多做题,即时自我反馈,用什么就学什么,总会有能做出所有十题的一天。



C. 稳定排序

大家都知道,快速排序是不稳定的排序方法。
如果对于数组中出现的任意a[i],a[j](i<j),其中a[i]==a[j],在进行排序以后a[i]一定出现在a[j]之前,则认为该排序是稳定的。

某高校招生办得到一份成绩列表,上面记录了考生名字和考生成绩。并且对其使用了某排序算法按成绩进行递减排序。现在请你判断一下该排序算法是否正确,如果正确的话,则判断该排序算法是否为稳定的。

Input

本题目包含多组输入,请处理到文件结束。
对于每组数据,第一行有一个正整数N(0<N<300),代表成绩列表中的考生数目。
接下来有N行,每一行有一个字符串代表考生名字(长度不超过50,仅包含'a'~'z'),和一个整数代表考生分数(小于500)。其中名字和成绩用一个空格隔开。
再接下来又有N行,是上述列表经过某排序算法以后生成的一个序列。格式同上。

Output

对于每组数据,如果算法是正确并且稳定的,就在一行里面输出"Right"。如果算法是正确的但不是稳定的,就在一行里面输出"Not Stable",并且在下面输出正确稳定排序的列表,格式同输入。如果该算法是错误的,就在一行里面输出"Error",并且在下面输出正确稳定排序的列表,格式同输入。

注意,本题目不考虑该排序算法是错误的,但结果是正确的这样的意外情况。

Sample Input

3
aa 10
bb 10
cc 20
cc 20
bb 10
aa 10
3
aa 10
bb 10
cc 20
cc 20
aa 10
bb 10
3
aa 10
bb 10
cc 20
aa 10
bb 10
cc 20

Sample Output

Not Stable
cc 20
aa 10
bb 10
Right
Error
cc 20
aa 10
bb 10

Code

#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    int n,i,j,p,q;
    while(scanf("%d",&n)!=EOF)
    {
        p=0;
        q=0;
        struct student
        {
            char name[52];
            int score;
        } c[n],d[n];
        struct student temp;
        for(i=0; i<n; i++)
            cin>>c[i].name>>c[i].score;
        for(i=1; i<n; i++)
        {
            temp=c[i];
            for(j=i-1;j>=0&&temp.score>c[j].score;j--)
            c[j+1]=c[j];
            c[j+1]=temp;
        }
        for(i=0; i<n; i++)
            {
                cin>>d[i].name>>d[i].score;
                if(d[i].score!=c[i].score) q=1;
                if(strcmp(d[i].name,c[i].name)!=0) p=1;
            }
        if(q==1)
        {
            cout<<"Error"<<endl;
            for(i=0; i<n; i++)
                cout<<c[i].name<<" "<<c[i].score<<endl;
            continue;
        }
        else if(p==1)
        {
            cout<<"Not Stable"<<endl;
            for(i=0; i<n; i++)
                cout<<c[i].name<<" "<<c[i].score<<endl;
            continue;
        }
        else cout<<"Right"<<endl;
    }
    return 0;
}



另外,TLE的D题如下

D. Stones

Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk back every evening. Walking may cause a little tired, so Sempr always play some games this time. 
There are many stones on the road, when he meet a stone, he will throw it ahead as far as possible if it is the odd stone he meet, or leave it where it was if it is the even stone. Now give you some informations about the stones on the road, you are to tell me the distance from the start point to the farthest stone after Sempr walk by. Please pay attention that if two or more stones stay at the same position, you will meet the larger one(the one with the smallest Di, as described in the Input) first. 

Input

In the first line, there is an Integer T(1<=T<=10), which means the test cases in the input file. Then followed by T test cases. 
For each test case, I will give you an Integer N(0<N<=100,000) in the first line, which means the number of stones on the road. Then followed by N lines and there are two integers Pi(0<=Pi<=100,000) and Di(0<=Di<=1,000) in the line, which means the position of the i-th stone and how far Sempr can throw it.

Output

Just output one line for one test case, as described in the Description.

Sample Input

2
2
1 5
2 4
2
1 5
6 6

Sample Output

11
12

Code


#include<stdio.h>
#include<iostream>
using namespace std;
struct stone
{
    int p;
    int d;
} c[100005],temp;
int main()
{
    int t,n,i,j,k,count,s;
    cin>>t;
    while(t--)
    {
        count=1;
        cin>>n;
        for(i=0; i<n; i++)
            cin>>c[i].p>>c[i].d;
        while(count<(2*n))
        {
            temp.p=100000;
            temp.d=0;
            for(i=0; i<n; i++)
            {
                if(c[i].p!=0&&c[i].p<temp.p)
                {
                    temp=c[i];
                    k=i;
                }
                if(c[i].p!=0&&c[i].p==temp.p&&c[i].d<temp.d)
                {
                    temp=c[i];
                    k=i;
                }
            }
            if(count%2==1)
                c[k].p+=c[k].d;
            else c[k].p=0;
            count++;
        }
        for(i=0; i<n; i++)
            if(c[i].p!=0) k=i;
        cout<<c[k].p<<endl;
    }
    return 0;
}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值