CSP2023-03
第一题
直接满分了:
#include <iostream> using namespace std ; const int N = 1e6 ; int n,a,b ; int panduan(int x1,int y1,int x2, int y2, int a,int b) { int c,k ; if( x2<0 || y2<0 || x1>a || y1>b ) return 0 ; // 在外侧 else { // 先判断x 左 中 右 if( x1<=0 && x2<=a ) c = x2 ; else if( x1>=0 && x2<=a ) c = x2-x1 ; else if( x1>=0 && x2>=a) c = a-x1 ; // 判断 y 上中下 if( y1>=0 && y2>=b) k = b-y1 ; else if(y1>=0 && y2<=b ) k = y2-y1; else if(y1<=0 && y2<=b) k = y2 ; } return c*k ; } int main(){ cin>>n>>a>>b ; int x1,y1,x2,y2 ; int sum =0 ; for(int i=0; i<n ; i++) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2) ; sum += panduan(x1,y1,x2,y2,a,b) ; } cout<<sum<<endl ; return 0 ; }
第二题
第一次提交只拿了 70分, 出现了超时错误,应该是每次都遍历所有点的问题
#include <iostream> #include <algorithm> using namespace std ; const int N = 1e6 ; int n,m,k ; struct tian{ int t,c ; }t[N] ; bool cmp(tian a, tian b) { return a.t>b.t ; } int main(){ cin>>n>>m>>k ; for(int i=0; i<n; i++) scanf("%d%d", &t[i].t, &t[i].c) ; sort(t,t+n,cmp) ; // 按照耗时进行排序 int max = t[0].t ; // 标记最大耗时 while(m>=0) { max -- ; // 提出要求 if( max < k) break ; // 达到最低线 for(int i=0 ; i<n ; i++) { if( t[i].t > max) { t[i].t-- ; m -= t[i].c ; } } } cout<<max+1 ; return 0 ; }
老师给的代码,可以100
第四题
混了10分,可能主要错误在没用上n吧
#include <iostream> #include <algorithm> #include <string> #include <cctype> #include <cstdlib> using namespace std; const int N = 1e8+10; int n,m ; long long int net[N] ; // 采用散列查找 int cvt(string a) { long long int na = 0 ; int k = 0; for(int i=0; i<a.size() ; i++) if(a[i]!=':') { if(a[i] == 'a') k = 10; else if(a[i] == 'b' ) k = 11; else if(a[i] == 'c' ) k = 12; else if(a[i] == 'd' ) k = 13; else if(a[i] == 'e' ) k = 14; else if(a[i] == 'f' ) k = 15 ; else k = int(a[i]-'0') ; na = (na + k)*16 ; } return na/16 ; } int main(){ cin>>n>>m ; int op, id; string a,b ; for(int i=0; i<m; i++) { cin>>op ; if(op == 1) { cin>>id>>a>>b; long long int l,r ; l = cvt(a) ; r = cvt(b) ; bool flag = true ; for(int i=l; i<=r ;i++) // 检查 { if(net[l] == id && net[r] == id) // 检查是否全分配完了 { cout<<"NO"<<endl; flag = false ; break ; } if(net[i]!=0 && net[i]!=id) { cout<<"NO"<<endl; flag = false ; break ; } } if(flag) //分配 { fill(net+l, net+r+1, id) ; cout<<"YES"<<endl; } } else if(op == 2) { cin>>a; long long int l = cvt(a) ; cout<<net[l]<<endl; } else { cin>>a>>b; long long int l,r ; l = cvt(a) ; r = cvt(b) ; int index = net[l]; bool flag = true; for(int i=l ;i<=r ;i++) { if(net[i]!=index) { flag = false ; cout<<0<<endl; break; } } if(flag) cout<<index<<endl; } } return 0 ; }
第五题
骗到了25分,错误是超时
#include <iostream> #include <cctype> using namespace std; const int N = 1e6+10; int n,m ; struct car{ int l,r ; }c[N] ; bool can(int l, int r, car c[], int m) { int a[N] = {0} ; // cout<<"进行"<<l<<"到"<<r<<endl ; for(int i=0; i<m; i++) { if( c[i].l >= l && c[i].r <= r) // 选取范围内的, 保证外围没施肥 { // cout<<" 选择小车 "<<c[i].l<<' '<<c[i].r<<endl; for(int j=c[i].l; j<=c[i].r; j++) { //cout<<"施肥"<<j<<endl ; a[j]++ ; } } } for(int i=l; i<=r ;i++) { //cout<<" 检查"<<i<<endl ; if(a[i]==0) { //cout<<"不满"<<endl ; return false ; } } //cout<<"满足"<<endl ; return true ; } int main(){ cin>>n>>m ; for(int i=0; i<m; i++) cin>>c[i].l>>c[i].r ; long long int cnt = n*(n-1)/2 ; //最大组合数 for(int i=1; i<=n; i++) { for(int j=i+1; j<=n; j++) // 遍历每一种组合 { if( !can(i,j,c,m) ) cnt-- ; } } cout<<cnt ; return 0 ; }
PS: 本文来自博客园,作者:尊滴菜,转载请注明原文链接:https://www.cnblogs.com/zundicai/p/17367115.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)