Codeforces Round #352 (Div. 2) A B C

来源:互联网 发布:mac maya5.0 编辑:程序博客网 时间:2024/05/16 10:56



链接:戳这里


A. Summer Camp
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.

This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.

Input
The only line of the input contains a single integer n (1 ≤ n ≤ 1000) — the position of the digit you need to print.

Output
Print the n-th digit of the line.

Examples
input
3
output
3
input
11
output
0
Note
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.

In the second sample, the digit at position 11 is '0', it belongs to the integer 10.


代码:

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include <ctime>#include<queue>#include<set>#include<map>#include<stack>#include<iomanip>#include<cmath>#define mst(ss,b) memset((ss),(b),sizeof(ss))#define maxn 0x3f3f3f3f#define MAX 1000100///#pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef unsigned long long ull;#define INF (1ll<<60)-1using namespace std;int n;string s;int main(){    for(int i=1;i<=9;i++) {        char c=i+'0';        s+=c;    }    for(int i=10;i<=99;i++){        char c=i/10+'0';        char cc=i%10+'0';        s+=c;        s+=cc;    }    for(int i=100;i<=999;i++){        char c=i/100+'0';        char cc=i/10%10+'0';        char ccc=i%10+'0';        ///2cout<<c<<" "<<cc<<" "<<ccc<<endl;        s+=c;        s+=cc;        s+=ccc;        ///cout<<s<<endl;    }    scanf("%d",&n);    cout<<s[n-1]<<endl;    return 0;}


B. Different is Good
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.

Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".

If string s has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.

Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.

Input
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.

The second line contains the string s of length n consisting of only lowercase English letters.

Output
If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.

Examples
input
2
aa
output
1
input
4
koko
output
2
input
5
murat
output
0
Note
In the first sample one of the possible solutions is to change the first character to 'b'.

In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".


代码:

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include <ctime>#include<queue>#include<set>#include<map>#include<stack>#include<iomanip>#include<cmath>#define mst(ss,b) memset((ss),(b),sizeof(ss))#define maxn 0x3f3f3f3f#define MAX 1000100///#pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef unsigned long long ull;#define INF (1ll<<60)-1using namespace std;int n;string s;int vis[33];int main(){    scanf("%d",&n);    cin>>s;    if(n>26) {        cout<<-1<<endl;        return 0;    }    int ans=0;    for(int i=0;i<s.size();i++){        if(!vis[s[i]-'a']){            vis[s[i]-'a']=1;            continue;        } else ans++;    }    cout<<ans<<endl;    return 0;}



C. Recycling Bottles
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.

We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can carry only one bottle at once each.
For both Adil and Bera the process looks as follows:
Choose to stop or to continue to collect bottles.
If the choice was to continue then choose some bottle and walk towards it.
Pick this bottle and walk to the recycling bin.
Go to step 1.
Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles.

They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin.

Input
First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.

The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.

Then follow n lines, each of them contains two integers xi and yi (0 ≤ xi, yi ≤ 109) — position of the i-th bottle.

It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct.

Output
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if .

Examples
input
3 1 1 2 0 0
3
1 1
2 1
2 3
output
11.084259940083
input
5 0 4 2 2 0
5
5 2
3 0
5 5
3 5
3 3
output
33.121375178000
Note
Consider the first sample.

Adil will use the following path: .

Bera will use the following path: .

Adil's path will be  units long, while Bera's path will be units long.


题意:

两个人在坐标轴上捡垃圾,每捡一个垃圾需要把它丢到垃圾箱去

给出A B C分别表示两个人的位置和垃圾箱的位置

要求把所有的垃圾捡完两个人最少走多少路程

注意 人可以选择不动


思路:

分三种情况考虑

1:只需要A去捡完所有的垃圾

2:只需要B去捡完所有的垃圾

3:A 和 B都去捡完所有的垃圾   

由于每次都要回到垃圾箱,所以可以直接在A B到达垃圾箱的时候看做一个人去捡 

每个人都存下帮助垃圾箱省下的最大和次大的距离


代码:

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include <ctime>#include<queue>#include<set>#include<map>#include<stack>#include<iomanip>#include<cmath>#define mst(ss,b) memset((ss),(b),sizeof(ss))#define maxn 0x3f3f3f3f#define MAX 1000100///#pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef unsigned long long ull;#define INF (1ll<<60)-1using namespace std;struct point{    long double x,y,dis;    int id;}s[100100],p[100100];int vis[100100];const long double eps=1e-8;int dcmp(long double x){    if(fabs(x)<=eps) return 0;    return x<0?-1:1;}long double disn(point a,point b){    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}bool cmp(point a,point b){    return dcmp(a.dis-b.dis)>0;}int n;int main(){    point A,B,C;    cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y;    scanf("%d",&n);    for(int i=1;i<=n;i++) cin>>s[i].x>>s[i].y;    long double ans1=0,ans2=0,ans3=0,mx1=-INF*1.0,mx2=mx1,ans=0,mx_1=mx1,mx_2=mx1;    for(int i=1;i<=n;i++) ans+=disn(s[i],C)*2;    int tmp1=-1,tmp2=-1;    for(int i=1;i<=n;i++){        long double d1=disn(A,s[i]);        long double d2=disn(C,s[i]);        long double d3=d2-d1;        if(dcmp(d3-mx1)>=0){            if(dcmp(mx1-mx_1)>=0) mx_1=mx1;            mx1=d3;            tmp1=i;        } else if(dcmp(d3-mx_1)>=0){            mx_1=d3;        }    }    ans1=ans-mx1;    for(int i=1;i<=n;i++){        long double d1=disn(B,s[i]);        long double d2=disn(C,s[i]);        long double d3=d2-d1;        if(dcmp(d3-mx2)>=0){            if(dcmp(mx2-mx_2)>=0) mx_2=mx2;            mx2=d3;            tmp2=i;        } else if(dcmp(d3-mx_2)>=0){            mx_2=d3;        }    }    ans2=ans-mx2;    /*cout<<tmp1<<" "<<tmp2<<endl;    cout<<setprecision(20)<<ans<<endl;    cout<<setprecision(20)<<ans1<<endl;    cout<<setprecision(20)<<ans2<<endl;    cout<<setprecision(20)<<mx1<<endl;    cout<<setprecision(20)<<mx_1<<endl;    cout<<setprecision(20)<<mx2<<endl;    cout<<setprecision(20)<<mx_2<<endl;*/    if(tmp1!=tmp2) ans3=ans-mx1-mx2;    else {        if(dcmp(mx1+mx_2-mx2-mx_1)>=0){            ans3=ans-mx1-mx_2;        } else ans3=ans-mx_1-mx2;    }    long double anw=INF*1.0;    anw=min(anw,ans1);    anw=min(anw,ans2);    anw=min(anw,ans3);    cout<<setprecision(20)<<anw<<endl;    return 0;}/*0 22 11 111 0*/


0 0
原创粉丝点击