2024初三集训模拟测试4
打了一场模拟赛
又没命了
2024初三集训模拟测试4
题目难度 T4 \(\le\) T2 \(\le\) T3 \(\le\) T1
T1 打赌
非常好题目,使我骰子旋转
定义三个变量记录当前状态:上,前,左
横着旋转,四个一循环, \(ans\) 直接加 $ 14 $
(模拟模拟模拟模拟) 模拟一下就可以
码
#include <bits/stdc++.h>
using namespace std;
int n,m;
long long ans=0;
int main(){
int up=1,left=4,front=2,t;
freopen("pogodak.in","r",stdin);
freopen("pogodak.out","w",stdout);
cin>>m>>n;
int cnt=n%4;
if(cnt){
for(int i=1;i<=m;i++){
// cout<<"A";
ans+=(n/4)*14;
ans+=up;
for(int j=1;j<cnt;j++){
t=left;
left=7-up;
up=t;
ans+=up;
}
t=up;
up=7-front;
front=t;
i++;
if(i>m)break;
ans+=(n/4)*14;
ans+=up;
for(int j=cnt-1;j>=1;j--){
t=left;
left=up;
up=7-t;
ans+=up;
}
t=up;
up=7-front;
front=t;
}
cout<<ans;
}
else{
cout<<n*14*m/4;
}
}
我在这道题上卡了两个小时,结果最后没过样例,还有 \(80 pts\)
$ \color {white} sb骰子怎么这么能转,模拟吐了 $
T2 舞会
额 鉴定为非触
诶,怎么会有人高达 $ -180 cm$ (蚌
先排序,再双指针跑一下就行了
码
#include <bits/stdc++.h>
using namespace std;
int boy[200000],girl[200000],ans;
bool cmp(int a,int b){
return a>b;
}
bool check(int a,int b){
if(a<b)swap(a,b);
if(a>0&&b<0&&a+b<0)
return 1;
return 0;
}
int main(){
int n;
freopen("party.in","r",stdin);
freopen("party.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++){
cin>>boy[i];
}
for(int i=1;i<=n;i++){
cin>>girl[i];
}
sort(boy+1,boy+n+1);
sort(girl+1,girl+n+1,cmp);
int end_l=1,end_r=1;
for(int i=1;i<=n;i++){
if(boy[i]>0){
end_l=i-1;
break;
}
end_l=i;
}
for(int i=1;i<=n;i++){
if(girl[i]<0){
end_r=i-1;
break;
}
end_r=i;
}
// cout<<end_l<<" "<<end_r<<endl;
int l=1,r=1;
while(l<=end_l&&r<=end_r){
if(check(boy[l],girl[r])){
ans++,l++,r++;
continue;
}
r++;
}
l=n;r=n;
while(l>end_l&&r>end_r){
if(check(boy[l],girl[r])){
ans++,l--,r--;
continue;
}
l--;
}
cout<<ans<<endl;
}
T3最小生成树
根据画图和打表可得此题求
\[\sum_{i=1}^{n} \varphi (i)
\]
不会线性筛,那就现学
码
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int p=100000007;
int vis[100000],prime[100000],phi[100000],ans=1,n,cnt;
void euler(int n){
memset(vis,0,sizeof vis);
phi[1]=1;
for(int i=2;i<=n;i++){
if(vis[i]==0){
prime[++cnt]=i;
phi[i]=i-1;
}
for(int j=1;j<=cnt && i*prime[j]<=n ;j++){
vis[i*prime[j]]=1;
if(i%prime[j]==0)
{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}else
phi[i*prime[j]]=phi[i]*(prime[j]-1);
}
}
}
signed main(){
freopen("mst.in","r",stdin);
freopen("mst.out","w",stdout);
cin>>n;
euler(n);
for(int i=1;i<=n;i++){
ans=ans*phi[i]%p;
}
cout<<ans;
}
买汽水
剪枝+爆搜
码
#include <bits/stdc++.h>
using namespace std;
int ans,n,m,w[100];
bool dfs(int x,int worth){
if(worth>m)return 0;
if(x==n+1){
if(worth==m){
cout<<m<<endl;
exit(0);
}
if(worth>ans && worth<=m)
ans=worth;
return 1;
}
if(!dfs(x+1,worth+w[x]));
dfs(x+1,worth);
return 1;
}
bool cmp(int a,int b){
return a>b;
}
int main(){
freopen ("drink.in","r",stdin);
freopen ("drink.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>w[i];
}
sort(w+1,w+n+1,cmp);
for(int i=n;i>=1;i--){
if(w[i]>m)n--;
}
dfs(0,0);
cout<<ans;
}