Codeforces Round #315 (Div. 2)

7069 단어 codeforces
[경기 링크]: 클릭 here~~
이번 시합은 가장 컨디션이 없는 것 같았다. 우선 첫 번째 문제는 한참 동안 보았는데, 주로 자신이 마음을 가라앉히지 않고 문제를 읽었기 때문에 이후에 좀 주의해야 한다.
Problem_A:
[제목]:
A. Music
time limit per test
 2 seconds
memory limit per test
 256 megabytes
input
 standard input
output
 standard output
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start.
Input
The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).
Output
Print a single integer — the number of times the song will be restarted.
Sample test(s)
input
5 2 2

output
2

input
5 4 7

output
1

input
6 2 3

output
1

Note
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
당신은 T초 길이의 노래를 들어야 합니다. 재생을 눌렀을 때 바로 S초를 다운로드합니다. 불러오지 않은 곳을 들었을 때 전체 노래를 들을 수 있을 때까지 다시 듣습니다. 네트워크가 막혀서 q초 안에 q-1초만 다운로드할 수 있습니다. 다시 몇 번을 눌러야 하는지 물어보고 첫 번째로 재생을 눌러도 됩니다.
【사고방식】 다운로드 속도를 알면 (q-1)/q, 우리가ts를 설치하여 다운로드하면 방정식이 있다. (q-1)/q*t+s=t화 간략화: t/q=(t-s)/(q-1)구해: t=q*s
그리고 코드는 아주 간단하게 지나갔어요. 그리고 오늘 보니까 어제는 안 지나갔어요.
코드:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int num[N];
int main()
{
    int  t,s,q;
    while(cin>>t>>s>>q)
    {
        int cnt=0;
        while(s<t)
        {
            cnt++;
            s*=q;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Problem_B:
[제목]:
B. Inventory
time limit per test
 1 second
memory limit per test
 256 megabytes
input
 standard input
output
 standard output
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.
During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering.
You have been given information on current inventory numbers for n items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to n by changing the number of as few items as possible. Let us remind you that a set ofn numbers forms a permutation if all the numbers are in the range from 1 to n, and no two numbers are equal.
Input
The first line contains a single integer n — the number of items (1 ≤ n ≤ 105).
The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — the initial inventory numbers of the items.
Output
Print n numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.
Sample test(s)
input
3
1 3 2

output
1 3 2 

input
4
2 2 3 3

output
2 1 3 4 

input
1
2

output
1 

Note
In the first test the numeration is already a permutation, so there is no need to change anything.
In the second test there are two pairs of equal numbers, in each pair you need to replace one number.
In the third test you need to replace 2 by 1, as the numbering should start from one.
하나의 수 n을 주고 n의 수 a[i]를 주면 a[i]에 중복되거나 n보다 큰 수가 있을 수 있으니 1~n의 배열을 요구합니다.
[사고방식] 중복된 숫자를 수조로 표시하고 a[i]에서 n보다 크고 n보다 작으며 중복된 숫자의 번호인 index를 기록한 다음에 1~n에 나타나지 않은 숫자로 바꾸면 된다.
코드:
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int num[N];
bool vis[N];
int arr[N];
int main()
{
    int t;
    while(~scanf("%d",&t))
    {
        memset(vis,false,sizeof(vis));
        memset(num,0,sizeof(num));
        memset(arr,0,sizeof(arr));
        int ll=0;
        for(int i=0; i<t; ++i) {
             scanf("%d",&num[i]);
          if(vis[num[i]]||num[i]>t) arr[ll++]=i;
          else if(!vis[num[i]]) vis[num[i]]=true;
        }
        int k=0;
        for(int i=1; i<=t; ++i)
        {
            if(!vis[i])
            {
               // cout<<"num[i]= "<<num[i]<<endl;
                num[arr[k++]]=i;
               // cout<<"arr[k++]="<<arr[k++]<<endl;
            }
        }
        for(int i=0; i<t; ++i)
        {
            printf("%d ",num[i]);
        }
        puts("");
    } return 0;
}


문제 해결

좋은 웹페이지 즐겨찾기