【比赛链接】:click here~~
这次的比赛感觉最没状态了,首先第一题就看了半天,主要是自己没有静下心来读题,以后得注意一下了
Problem_A:
【题意】:
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.
The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).
Print a single integer — the number of times the song will be restarted.
5 2 2
2
5 4 7
1
6 2 3
1
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
然后代码就非常easy的过了,然后今天发现昨天的竟然没有过~~
代码:
#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:
【题意】:
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.
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.
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.
3
1 3 2
1 3 2
4
2 2 3 3
2 1 3 4
1
2
1
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; }
problem c 待补~~