P10385 [蓝桥杯 2024 省 A] 艺术与篮球 填空题,考的闰年知识。
https://www.luogu.com.cn/problem/P10385
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 #include <bits/stdc++.h> using namespace std;#define int long long using ll =long long ;int s[11 ]={13 ,1 ,2 ,3 ,5 ,4 ,4 ,2 ,2 ,2 };signed main () { ios::sync_with_stdio (0 ); cin.tie (0 ); int i=2000 ,j=1 ,k=1 ; int cnt=0 ; while (1 ) { int sum=0 ; for (int cheng=10 ;cheng<=10000 ;cheng*=10 ) { sum+=s[i%cheng/(cheng/10 )]; } for (int cheng=10 ;cheng<=100 ;cheng*=10 ) { sum+=s[j%cheng/(cheng/10 )]; } for (int cheng=10 ;cheng<=100 ;cheng*=10 ) { sum+=s[k%cheng/(cheng/10 )]; } if (sum>50 )cnt++; if (i==2024 &&j==4 &&k==13 ) { cout<<cnt<<'\n' ; return 0 ; } k++; if ((j<=7 &&j%2 ==1 )||(j>7 &&j%2 ==0 )) { if (k>31 ) { k=1 ; j++; if (j>12 ) { j=1 ; i++; } } } else if (j==2 ) { if ((i%4 ==0 &&i%100 !=0 )||(i%400 ==0 )) { if (k>29 ) { k=1 ; j++; if (j>12 ) { j=1 ; i++; } } } else { if (k>28 ) { k=1 ; j++; if (j>12 ) { j=1 ; i++; } } } } else { if (k>30 ) { k=1 ; j++; if (j>12 ) { j=1 ; i++; } } } } return 0 ; }
P10386 [蓝桥杯 2024 省 A] 五子棋对弈 https://www.luogu.com.cn/problem/P10386
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 #include <bits/stdc++.h> using namespace std;int main () { cout<<3126376 <<'\n' ; return 0 ; }
P10387 [蓝桥杯 2024 省 A] 训练士兵 https://www.luogu.com.cn/problem/P10387
比较基础的模拟+思维
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 #include <bits/stdc++.h> using namespace std;using u32 = unsigned ;#define i128 __int128; using ll = long long ;#define int ll using u64 = unsigned long long ;const ll inf = 1e9 ;const ll INF = 1e18 ;const int N=1e5 +10 ;int a[N],b[N];pair<int ,int >v[N]; int pre[N];signed main () { ios::sync_with_stdio (false ); cin.tie (nullptr ); int n,s; cin>>n>>s; for (int i=1 ;i<=n;i++)cin>>v[i].first>>v[i].second; sort (v+1 ,v+1 +n,[&](pair<int ,int >&a,pair<int ,int >&b){ return a.second>b.second; }); for (int i=1 ;i<=n;i++) { a[i]=v[i].first; b[i]=v[i].second; } int sum=0 ; for (int i=1 ;i<=n;i++)pre[i]=pre[i-1 ]+a[i]; int wei=upper_bound (pre+1 ,pre+1 +n,s)-pre; int gao=b[wei]; for (int i=1 ;i<wei;i++) { sum+=1ll *(b[i]-gao)*a[i]; } sum+=1ll *gao*s; cout<<sum<<'\n' ; return 0 ; }
P10389 [蓝桥杯 2024 省 A] 成绩统计 https://www.luogu.com.cn/problem/P10389
这一题让在一个给定的区间内挑k个数使得方差最小,我们需要知道的是最优策略一定是排序之后挑k个连续的数才行。这样就简单多了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 #include <bits/stdc++.h> using namespace std;using u32 = unsigned ;#define i128 __int128; using ll = long long ;#define int ll using u64 = unsigned long long ;const ll inf = 1e9 ;const ll INF = 1e18 ;const int N=1e5 +10 ;int a[N],v[N];int sum_s[N],sum[N];int n,k,t;bool check (int m) { for (int i=1 ;i<=m;i++)v[i]=a[i]; sort (v+1 ,v+1 +m); for (int i=1 ;i<=m;i++) { sum_s[i]=sum_s[i-1 ]+1ll *v[i]*v[i]; sum[i]=sum[i-1 ]+v[i]; } double ans=DBL_MAX; for (int i=k;i<=m;i++) { double sum1=sum_s[i]-sum_s[i-k]; double sum2=2 *(1.0 *sum[i]-sum[i-k])*((1.0 *sum[i]-sum[i-k])/k); double sum3=((1.0 *sum[i]-sum[i-k])/k)*((1.0 *sum[i]-sum[i-k])/k)*k; ans=min (ans,(sum1-sum2+sum3)/k); } return ans<t; } signed main () { ios::sync_with_stdio (false ); cin.tie (nullptr ); cin>>n>>k>>t; for (int i=1 ;i<=n;i++)cin>>a[i]; int l=k-1 ,r=n+1 ,ans=-1 ; while (r-l>1 ) { int mid=(l+r)>>1 ; if (check (mid)) { r=mid; } else { l=mid; } } cout<<(r==n+1 ?-1 :r)<<'\n' ; return 0 ; }