1.A 画牌河
根据题意模拟即可
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
using namespace std;
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz(a) (int) (a).size()
#define endl "\n"
void solved() {
int n;
cin>>n;
for(int i=1;i<=18;i++){
if(n) cout<<1,n--;
else cout<<0;
if(i%6==0) cout<<endl;
}
return ;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solved();
return 0;
}
2.B/D 不点二面
模拟:
对于每个可以到达的数进行计数,如果cnt[x]==0那么我们就将答案减一,如果cnt[x]第一次出现我们就把答案+1。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
using namespace std;
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz(a) (int) (a).size()
#define endl "\n"
void solved() {
int m,q;
cin>>m>>q;
map<int,int> cnt;
int t=0;
while(q--){
int op,x;
cin>>op>>x;
if(op==1){
if(!cnt[x+3]&&x+3<=m) t++;
if(!cnt[x-3]&&x-3>=1)t++;
if(x+3<=m) cnt[x+3]++;
if(x-3>=1) cnt[x-3]++;
}
if(op==2){
if(x+3<=m) cnt[x+3]--;
if(x-3>=1) cnt[x-3]--;
if(x-3>=1&&cnt[x-3]==0) t--;
if(x+3<=m&&cnt[x+3]==0) t--;
}
cout<<t<<endl;
}
return ;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solved();
return 0;
}
3. C.一刀二分三角
二分/数学:
如果想要避免使用高精度,直接用二分来判断X的可行性就行了,因为随着X的增加,面积具有单调性
还有一种O(1)的做法:
需要用到double,但是要考虑精度问题
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
using namespace std;
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz(a) (int) (a).size()
#define endl "\n"
int xb,xc,yc;
bool check(int mid){
int l=mid;
if(mid>xc){
if(xb*(xb-xc)<=2*(xb-l)*(xb-l)){
return 1;
}
}
else{
if(xb*xc>=2*l*l){
return 1;
}
}
return 0;
}
void solved() {
cin>>xb>>xc>>yc;
int l=0,r=xb;
while(l<r){
int mid=(l+r+1)>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
if(l>xc){
if(xb*(xb-xc)==2*(xb-l)*(xb-l)){
cout<<"YES"<<endl;
return ;
}
}
else{
if(xc*xb==2*l*l){
cout<<"YES"<<endl;
return ;
}
}
cout<<"NO"<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
solved();
}
return 0;
}
E.游戏的买
期望dp
倒推即可:用dp[i]表示前i-1天没买的情况,很容易想到 dp[i]=min(dp[i+1],a[i])/2+min(dp[i+1],b[i])/2;
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
using namespace std;
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz(a) (int) (a).size()
#define endl "\n"
void solved() {
int n;
cin>>n;
vector<double> a(n+1),b(n+1);
vector<double> dp(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++) cin>>b[i];
dp[n]=(a[n]+b[n])/2;
for(int i=n-1;i>=1;i--){
dp[i]=min(dp[i+1],a[i])/2.0+min(dp[i+1],b[i])/2.0;
}
cout<<dp[1]<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
solved();
}
return 0;
}