
A題
A題——Pens and Pencils
這個題寫的是比較快的,但是問題是在下的英文實在是不咋樣,所以我讀題本身就慢好多。但是努力學(xué)習(xí)就好了。
這個題目當(dāng)時看完給我感覺就是暴力,注意一點就是
eg:三場講座一根pen剛好,但是四場就不夠了,但是第二根pen用不完,我們這里是進(jìn)一不四舍五入。我們需要2個pen。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int a,b,c,d,k;
cin>>a>>b>>c>>d>>k;
int sum1,sum2;
sum1=(a-1)/c+1;
sum2=(b-1)/d+1;
if(sum1+sum2>k)
cout<<"-1"<<endl;
else
cout<<sum1<<" "<<sum2<<endl;
}
return 0;
}

B題
B題——Rooms and Staircases
思路:
如果沒有梯子,那么我們最多只能將一行完全走完,最多的結(jié)果為n
但是一旦有了梯子(假設(shè)在第k間房子),也就是說我們能形成一二層之間的通道,假設(shè)我們是從二樓左邊開始出發(fā),遇到梯子就下來,讓后在一樓繼續(xù)朝左側(cè)行駛,也就是說從左側(cè)開始到左側(cè)結(jié)束。我們會有兩結(jié)果,一個梯子左邊,2(k)個房間。另外一個是2(n-k+1)個房間。最終只需要比較大小輸出即可。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
int k;
cin>>n;
string s;
cin>>s;
k=s.find('1');
int r=s.rfind('1');
if(k==-1)
cout<<n<<endl;
else
cout<<max(r+1,n-k)*2<<endl;
}
return 0;
}

C題
C題——The Football Season
注意一點:
輸入數(shù)據(jù)w>d;
因為d<w,那么可以知道y<w,因為當(dāng)y≥w時,w個d不如x=d時,d個w劃算。
然后w的范圍也比較小,所以直接枚舉判斷就是了。
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main ()
{
cin.tie(nullptr);
cout.tie(nullptr);
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
ll n, p, w, d;
cin >> n >> p >> w >> d;
for (ll y = 0; y <= w; y++) {
ll sum = p - y*d;
if (sum < 0)
continue;
if (sum % w == 0) {
ll x = sum / w;
ll z = n-x-y;
if (z >= 0) {
cout << x << ' ' << y << ' ' << z;
return 0;
}
}
}
cout << -1;
return 0;
}