Codeforces Round #525 (Div. 2)B. Ehab and subtraction
B. Ehab and subtraction
題目連結:https://codeforc.es/contest/1088/problem/B
題意:
給出n個數,給出k次操作,然後每次操作把所有數減去最小值,輸出這個最小值,k用不完用0來補。
題解:
考慮到重複的數會被一起減去,所以我用了個set來存放這n個數,然後用個累加器記錄下減去了多少最小值,把數取出來時減去這個累加器就好了,最後用0來補。
程式碼如下:
#include <bits/stdc++.h> using namespace std; const int N = 1e5+5; int n,k;int a[N]; set <int > S; int main(){ cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); for(int i=1;i<=n;i++) S.insert(a[i]); int cnt=0; for(auto it=S.begin();it!=S.end();it++){ cout<<*it-cnt<<endl; cnt+=*it-cnt; k--; if(k<=0) break; } while(k--) cout<<0<<endl; return 0; }
相關推薦
Codeforces Round #525 (Div. 2)B. Ehab and subtraction
B. Ehab and subtraction 題目連結:https://codeforc.es/contest/1088/problem/B 題意: 給出n個數,給出k次操作,然後每次操作把所有數減去最小值,輸出這個最小值,k用不完用0來補。 題解: 考慮到重複的數會被一起減去,所以我用了個set
Codeforces Round #525 (Div. 2) B. Ehab and subtraction
題解 題目大意 給一個數列n 每次將其中最小的元素取出並輸出 整個序列非0元素全部減去這個最小元素往復操作k次 將陣列排序併除重 因為如果元素相同肯定減去之後另一個為0 記錄一個減去的量每次取出最小的 輸出值-減去量 AC程式碼 #include <stdio.h>
Codeforces Round #525 (Div. 2) D - Ehab and another another xor problem(互動題之猜數)
題意 互動題,要猜a和b,你輸入c和d, 記e=a異或c,f=b異或d e>f返回1,e==f返回0,e<f返回-1 給你最多62次機會,要求猜出a和b 思路來源 https://blog.csdn.net/weixin_43790474/article/d
Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task(數論構造)
思路來源 http://www.cnblogs.com/Dup4/p/10068891.html 題解 注意%可以起到等同於減的作用。 Solution1: 先給區間[1,n]加上一個較大的數D,比如500W, 這樣ai就變為D+ai, 由於ai-i<1
Codeforces Round #525 (Div. 2)A. Ehab and another construction problem
滿足 hab i++ col std other ext pro con A. Ehab and another construction problem 題目鏈接:https://codeforc.es/contest/1088/problem/A 題意: 給出一個
Codeforces Round #525 (Div. 2)C. Ehab and a 2-operation task
一個數 n-1 i++ 我們 text ++ target sin const C. Ehab and a 2-operation task 題目鏈接:https://codeforc.es/contest/1088/problem/C 題意: 給出n個數,然後最多可
Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task
題意: 給定一個長度為 n 的陣列a[ ],並且有兩種操作: ①將前 i 個數全都加上 x; ②將前 i 個數全都 mod x 要求用不超過 n+1 次操作,使得陣列 a[ ] 嚴格單調遞增。 思路: 對於每個數a[ i ],實施操作 a[ i ]%( a[ i ]-i
Codeforces Round #525 (Div. 2) F. Ehab and a weird weight formula
F. Ehab and a weird weight formula 題目連結:https://codeforces.com/contest/1088/problem/F 題意: 給出一顆點有權值的樹,滿足只有一個點的權值最小,然後除開這個點,每個點都有一個權值比它更小的點與之相鄰。 然後要求你重構這
Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(互動題 異或)
題目 題意: 0≤a,b<2^30, 最多猜62次。 互動題,題目設定好a,b的值,要你去猜。要你通過輸入 c d : 如果 a^c < b^d ,會反饋 -1 ; 如果 a^c = b^d ,會反饋 0 ; 如果 a^c
Codeforces Round #525 (Div. 2)C - Ehab and a 2-operation task
題目 題意: 給你長度為n的陣列a[i],最多操作n+1次,每次都可以將前 i 個數 (操作1)都加上x,或者(操作2)都%x ,(x為1e6以內的任意數,且每次操作可以不同), 使得陣列a嚴格單調遞增(一定後一項大於前一項)。 要你輸出一個總的
Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem 互動 二進位制 思維
題解 互動題 題目大意 有兩個數字a和b要你去猜 你可以詢問兩個數字c和d 系統會反饋給你a ^ c和b ^ d的大小比較結果 左邊大1右邊大-1相同0 最多猜62次 數值範圍小於2的30次方 說明最多有30個二進位制位 最開始使用一次確定a和b的大小關係 每個二進位制位使用兩次猜測
Codeforces Round #525 (Div. 2) A. Ehab and another construction problem
題解 題目大意 給一個n找到滿足四個條件式的a和b a和b可以相等 除了1都可以找到a=b=n這種情況滿足條件 AC程式碼 #include <stdio.h> #include <bits/stdc++.h> using namespace std;
Codeforces Round #525 (Div. 2) F. Ehab and a weird weight formula(思維+貪心)
F. Ehab and a weird weight formula time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input output sta
Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem(貪心+樹形dp)
E. Ehab and a component choosing problem time limit per test 1 second memory limit per test 256 megabytes input standard input output
Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(思維)
D. Ehab and another another xor problem time limit per test 1 second memory limit per test 256 megabytes input standard input output s
Codeforces Round #525 (Div. 2)—E. Ehab and a component choosing problem(樹形dp)
E. Ehab and a component choosing problem time limit per test 1 second memory limit per test 256 megabytes input standard input output
Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task 數學 mod運算的性質
n) 一個 val 數學 註意 兩種 pmod 使用 back C. Ehab and a 2-operation task 數學 mod運算的性質 題意: 有兩種對前綴的運算 1.對前綴每一個$a +x$ 2.對前綴每一個$a\mod(x)$ 其中x任選 思路:這裏只有加
Codeforces Round #442 (Div. 2) B. Nikita and string
style force c++ its class char 每次 包含 子串 題意:給一個字符串,問形如a……a/ /b……b/ /a……a的子串最大長度 題解:設三個狀態a,ab,aba分別表示對應長度。因為每段長度可以為0,所以後一個狀態的包含前一個狀態。每次更新
Codeforces Round #267 (Div. 2) B. Fedor and New Game【位運算/給你m+1個數讓你判斷所給數的二進制形式與第m+1個數不相同的位數是不是小於等於k,是的話就累計起來】
ons ecif 否則 ans contain rst rmi sum any After you had helped George and Alex to move in the dorm, they went to help their friend
Codeforces Round #524 (Div. 2) B. Margarite and the best present 規律題
B. Margarite and the best present time limit per test 1 second memory limit per test 256 megabytes input standard input output stand