a. mashmokh and lights
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
mashmokh works in a factory. at the end of each day he must turn off all of the lights.
the lights on the factory are indexed from 1 to n. there are n buttons in mashmokh's room indexed from 1 to n as well. if mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
mashmokh is not very clever. so instead of pushing the first button he pushes some of the buttons randomly each night. he pushed mdistinct buttons b1,?b2,?...,?bm (the buttons were pushed consecutively in the given order) this night. now he wants to know for each light the index of the button that turned this light off. please note that the index of button bi is actually bi, not i.
please, help mashmokh, print these indices.
input
the first line of the input contains two space-separated integers n and m (1?≤?n,?m?≤?100), the number of the factory lights and the pushed buttons respectively. the next line contains m distinct space-separated integers b1,?b2,?...,?bm (1?≤?bi?≤?n).
it is guaranteed that all lights will be turned off after pushing all buttons.
output
output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
sample test(s)
input
5 44 3 1 2
output
1 1 3 4 4
input
5 55 4 3 2 1
output
1 2 3 4 5
note
in the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. then after pressing button number 3, light number 3 is turned off as well. pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
分析:弄一个数组,开始初始化为-1,然后每次开关某light,就把比它大的还是-1的值设为该开关
代码:
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;typedef long long ll;const int n=100010;int arr[n];int n;int main(){ while(cin>>n) { int m; for(int i=1;i>m; for(int i=0;i>b; for(int j=b;j<=n;j++) { if(arr[j]==-1) arr[j]=b; } } for(int i=1;i<=n;i++) cout<
b. mashmokh and tokens
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
bimokh is mashmokh's boss. for the following n days he decided to pay to his workers in a new way. at the beginning of each day he will give each worker a certain amount of tokens. then at the end of each day each worker can give some of his tokens back to get a certain amount of money. the worker can save the rest of tokens but he can't use it in any other day to get more money. if a worker gives backw tokens then he'll get dollars.
mashmokh likes the tokens however he likes money more. that's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. he has n numbers x1,?x2,?...,?xn. number xi is the number of tokens given to each worker on the i-th day. help him calculate for each of n days the number of tokens he can save.
input
the first line of input contains three space-separated integers n,?a,?b (1?≤?n?≤?105; 1?≤?a,?b?≤?109). the second line of input containsn space-separated integers x1,?x2,?...,?xn (1?≤?xi?≤?109).
output
output n space-separated integers. the i-th of them is the number of tokens mashmokh can save on the i-th day.
sample test(s)
input
5 1 412 6 11 9 1
output
0 2 3 1 1
input
3 1 21 2 3
output
1 0 1
input
1 1 11
output
分析:数学题,不要理解错题意就行,反正就是不要多拿没用的来token来换钱就行
代码:
#include int n, a, b, x[100000];int main(){ scanf(%d%d%d, &n, &a, &b); for(int i = 0; i n>>k; if(n==1) { if(k==0) cout<<1<
