生活随笔
收集整理的這篇文章主要介紹了
Codeforces edu 88(A~E)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
A題.Berland Poker
讀懂題意即可
代碼:
#include <bits/stdc++.h>
#define ll long long
using namespace std
;int main()
{ll t
,n
,m
,k
;scanf("%lld",&t
);while(t
--){scanf("%lld %lld %lld",&n
,&m
,&k
);ll op
=n
/k
;if(m
<=op
){printf("%lld\n",m
);continue;}else{ll ans
=op
;m
-=op
;ll u
=k
-1;if(m
%u
==0){printf("%lld\n",ans
-m
/u
);}else{ans
=ans
-(m
/u
+1);printf("%lld\n",ans
);}}}return 0;
}
B題.New Theatre Square
只能選1 x 1 或 1 x 2的,如果1x1的價格的兩倍小于1x2的,那么就全部用1x1的,否則能用1x2的就用1x2的
代碼:
#include <bits/stdc++.h>
#define ll long long
using namespace std
;char s
[105][10005];
int main()
{ll t
,n
,m
,k
,x
,y
;scanf("%lld",&t
);while(t
--){scanf("%lld %lld %lld %lld",&n
,&m
,&x
,&y
);for(int i
=0;i
<n
;i
++){scanf("%s",s
[i
]);}if(2*x
<=y
){ll cnt
=0;for(int i
=0;i
<n
;i
++){for(int j
=0;j
<m
;j
++){if(s
[i
][j
]=='.'){cnt
++;}}}printf("%lld\n",cnt
*x
);}else{ll sx
=0,sy
=0;for(int i
=0;i
<n
;i
++){int j
=0;while(j
<m
){if(j
<m
-1){if(s
[i
][j
]=='.'&&s
[i
][j
+1]=='.'){sy
++;j
+=2;continue;}if(s
[i
][j
]=='.'&&s
[i
][j
+1]!='.'){sx
++;j
++;continue;}j
++;}else{if(s
[i
][j
]=='.'){sx
++;j
++;continue;}j
++;}}}printf("%lld\n",sx
*x
+sy
*y
);}}return 0;
}
C題.Mixing Water
題意:有兩種水,一種熱水溫度為h,一種涼水溫度為c,只能按照一杯熱水、一杯涼水、一杯熱水、一杯涼水······的順序添加到同一個桶中,問最少需添加幾次,使得桶中水的平均溫度最接近t
思路:因為精度問題WA了兩次很難受,這題推一個式子即可,當添加次數為偶數時,桶內溫度一定為(h+c)/2
設當添加次數為j,且j為奇數時,可得到這樣一個式子:(((j-1)/2)*(h+c)+h)/j=t
這樣可以把 j 解出來,j可能是個浮點數,只是個模糊數值吧,把j附近的整數枚舉一遍求出最終的答案
代碼:
#include <bits/stdc++.h>
#define ll long long
using namespace std
;char s
[105][10005];
int main()
{ll t
,h
,c
,f
;scanf("%lld",&t
);while(t
--){scanf("%lld %lld %lld",&h
,&c
,&f
);if(h
<=f
){printf("1\n");continue;}double hh
=h
*1.0;double cc
=c
*1.0;double ff
=f
*1.0;double op
=(hh
+cc
)/2.0;if(ff
<=op
){printf("2\n");continue;}double ans
=(hh
-cc
)/(ff
*2.0-hh
-cc
);double opc
=ff
-op
;ll df
=ans
;ll pos
;double minn
=99999999.0;for(ll i
=df
-3;i
<=df
+3;i
++){if(i
<=0){continue;}if(i
%2==0){double uu
=ff
-op
;if(uu
<=minn
){pos
=i
;minn
=uu
;}}else{double ee
=(((i
-1)/2)*(h
+c
)*1.0+h
*1.0)/(i
*1.0);double uu
=fabs(ee
-ff
);if(uu
<minn
){pos
=i
;minn
=uu
;}}}if(pos
%2==0){printf("2\n");}else{printf("%lld\n",pos
);}}return 0;
}
待更新·································先打lol去了
D題.Yet Another Yet Another Task
又是最后剩下半個小時,寫了個假DP WA了好幾次,唉。。。。
題意:求一段區間,使該區間去掉一個最大值后的區間和值最大,問區間和最大值是多少
思路:因為ai<=30,直接從0到30枚舉最大值,對每次最大值求最大子段和
代碼:
#include <bits/stdc++.h>
#define ll long long
using namespace std
;ll a
[200005],d
[200005];
int main()
{ll n
;scanf("%lld",&n
);for(int i
=1;i
<=n
;i
++){scanf("%lld",&a
[i
]);}ll ans
=-9999999999999;for(int i
=0;i
<=30;i
++){ll maxx
=-9999999999999;for(int j
=1;j
<=n
;j
++){if(a
[j
]>i
){d
[j
]=0;}else{d
[j
]=max(d
[j
-1]+a
[j
],(ll
)0);maxx
=max(maxx
,d
[j
]);}}ans
=max(ans
,maxx
-i
);}printf("%lld\n",ans
);return 0;
}
E題.Modular Stability
題意:給你一個n和k,要求在1~n內取k個數,對于任何正數x,x%這k個數任何排列方式后的值相同,問有多少種取法
思路:仿照樣例1打個表,差不多就知道是咋回事了
再用組合數和逆元求出最終結果
代碼:
#include <bits/stdc++.h>
#define ll long long
using namespace std
;ll mod
=998244353,bb
=1;
void init(ll r
)
{for(ll i
=r
;i
>=1;i
--){bb
=bb
*i
%mod
;}
}
ll
apow(ll a
,ll b
)
{ll s
=1;while(b
){if(b
&1){s
=s
*a
%mod
;}a
=a
*a
%mod
;b
>>=1;}return s
%mod
;
}
ll
C(ll n
,ll r
)
{ll aa
=1;for(ll i
=n
;i
>=n
-r
+1;i
--){aa
=aa
*i
%mod
;}return aa
*apow(bb
,mod
-2)%mod
;
}
int main()
{ll n
,k
;cin
>>n
>>k
;if(n
==k
){cout
<<"1"<<endl
;return 0;}if(n
<k
){cout
<<"0"<<endl
;return 0;}if(k
==1){cout
<<n
<<endl
;return 0;}init(k
-1);ll ans
=0;for(ll i
=1;i
<=n
;i
++){if(i
+k
>n
){break;}ll maxx
=n
/i
;if(maxx
<k
){continue;}ans
=(ans
%mod
+C(maxx
-1,k
-1)%mod
)%mod
;}cout
<<ans
<<endl
;return 0;
}
總結
以上是生活随笔為你收集整理的Codeforces edu 88(A~E)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。