題目大意:
給你一個,要你求,其中,。
思路:
這題一開始我項會不會有循環節,因爲樣例相同。然後寫了後面幾項發現並不是。不難發現如果出現就可以直接不用算了,但是如果一直不出現就很尷尬,但是沒不到其他思路了就按照找寫了一發,就了,證明不太會。。。。
代碼:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 2e5 + 10;
void solved(){
int t;cin>>t;
while(t--){
ll a1,k;cin>>a1>>k;
set<int>st;
ll temp = a1;
int maxx = 0,minn = 10;
while(a1 > 0){
maxx = max(maxx,(int)(a1 % 10));
minn = min(minn,(int)(a1 % 10));
st.insert(a1 % 10);
a1 /= 10;
}
ll tot = 1;
while(tot < k && st.find(0)==st.end()){
tot++;
temp = temp + maxx * minn;
ll t = temp;
int minnn = 10,maxxx = 0;
while(t > 0){
maxxx = max(maxxx,(int)(t % 10));
minnn = min(minnn,(int)(t % 10));
st.insert(t % 10);
t /= 10;
}
maxx = maxxx;minn = minnn;
}
cout<<temp<<endl;
}
}
int main(){
solved();
return 0;
}
題目大意:
給你一個長度爲的序列,表示第個人的經驗值,現在你要對他們進行分組,當每組人數就可以加入這組,現在要你求最多能分多少組?
思路:
這個題好像很顯然,看題+寫代碼不到分鐘就了。就統計一下的人數,然後這樣分配肯定是最優的, % 可能不爲0,所以再用一個變量表示剩餘人數就行,剩餘人可以加到別的組。
代碼:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 2e5 + 10;
int cnt[maxn];
void solved(){
int t;cin>>t;
while(t--){
int n;cin>>n;
for(int i = 1; i <= n; i++)cnt[i] = 0;
for(int i = 1; i <= n; i++){
int a;cin>>a;cnt[a]++;
}
int ans = 0,rest = 0;
for(int i = 1; i <= n; i++){
ans += (cnt[i] + rest) / i;
rest = (cnt[i] + rest) % i;
}
cout<<ans<<endl;
}
}
int main(){
solved();
return 0;
}
題目大意:
給你四個數:,然後要你找三條邊,滿足他們是一個非退化三角形,求非退化三角形的個數。
思路:
這個題也很簡單,非退化三角形指的是面積爲0不共線的三角形,通俗的講就是。先枚舉的個數,然後在找有多少個數滿足就行了。統計個數要區間用個差分就行了。注意要開LL.
代碼:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 5e5 + 10;
ll cnt[maxn << 1 | 1];
void solved(){
ll a,b,c,d;cin>>a>>b>>c>>d;
for(ll i = a; i <= b; i++){
cnt[i + b]++;cnt[i + c + 1]--;
}
for(ll i = 1; i <= maxn << 1; i ++)cnt[i] += cnt[i - 1];
ll ans = 0;
for(ll i = 1; i <= maxn << 1; i++){
ans += cnt[i] * max(0LL,(min(d,i - 1) - c + 1));
}
cout<<ans<<endl;
}
int main(){
solved();
return 0;
}
題目大意:
要你構造一個長度爲的序列使得他們的和爲。現在你指定一個數,問選擇一段連續的區間的和能不能得到,如果能,輸出“NO”,非則輸出"YES",並且輸出你構造的數組以及。
思路:
構造一個數組選。
代碼:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int cnt[maxn];
void solved(){
int n,s;cin>>n>>s;
int l1 = 1,r1 = n - 1;
int l2 = s - (n - 1),r2 = s;
for(int i = l1 ; i <= r1; i++)cnt[i]=1;
for(int i = l2 ; i <= r2; i++)cnt[i]=1;
int ans = -1;
for(int i = 1; i <= n; i++){
if(cnt[i] == 0){
ans = i;break;
}
}
if(ans != -1){
cout<<"YES"<<endl;
for(int i = 1; i <= n - 1; i++){
cout<<"1"<<" ";
}
cout<<s - (n - 1)<<endl;
cout<<ans<<endl;
}else{
cout<<"NO"<<endl;
}
}
int main(){
solved();
return 0;
}