The 6th Zhejiang Provincial Collegiate Programming Contest

本文提供了几种经典的算法题解,包括使用稳定排序解决第二价格拍卖问题、利用三分法解决精度问题、借助集合处理字符串数据、通过模拟解决问题是否可以用栈或队列实现等。

Second-price Auction :稳定排序水过。

#include<iostream> #include<cstdio> #include<algorithm> #include<cstdio> using namespace std; class node { public: int no,date; }; node tree[105]; bool cmp(node a,node b) { if(a.date >b.date )return true; return false; } int main() { int t,n,i; cin>>t; while(t--) { cin>>n; for(i=1;i<=n;i++) { scanf("%d",&tree[i].date ); tree[i].no =i; } sort(tree+1,tree+1+n,cmp); printf("%d %d\n",tree[1].no ,tree[2].date ); } return 0; }

Light Bulb:三分法。注意精度问题。

#include<iostream> #include<cstdio> #include<string> using namespace std; #define esp 1e-6 double H,h,D; double suc(double x) { return (h*D-H*x)/(D-x)+x; } int main() { int t; cin>>t; while(t--) { cin>>H>>h>>D; double left=0,right=D*h/H; while(right-esp>left) { double mid=(left+right)/2.0; double midmid=(mid+right)/2.0; double c1=suc(mid); double c2=suc(midmid); if(c1>=c2) right=midmid; else left=mid; } printf("%.3lf\n",suc(left)); } return 0; }

80ers' Memory:这种题,很适合用set。

#include<iostream> #include<string> #include<cstdio> #include<set> using namespace std; set<string>tree; int main() { int flag,n,i,k; string str; cin>>n; for(i=0;i<n;i++) { cin>>str; tree.insert (str); } cin>>k; while(k--) { cin>>n; flag=0; while(n--) { cin>>str; if(tree.find (str)!=tree.end ()) flag++; } printf("%d\n",flag); } return 0; }

A Stack or A Queue?:模拟题。

#include<iostream> #include<cstdio> #include<string> #include<stack> #include<queue> #include<vector> using namespace std; int a1[105],a2[105]; int main() { int t,i,n,k; cin>>t; while(t--) { queue<int> q; stack<int> st; cin>>n; for(i=1;i<=n;i++) { scanf("%d",&a1[i]); q.push (a1[i]); st.push (a1[i]); } for(i=1;i<=n;i++) scanf("%d",&a2[i]); i=1; while(!q.empty ()) { if(a2[i]==q.front ()) { i++; q.pop (); } else break; } i=1; while(!st.empty ()) { if(a2[i]==st.top ()) { i++;st.pop ();} else break; } if(q.empty ()&&st.empty ()) cout<<"both"<<endl; else if(q.empty ()&&!st.empty ()) cout<<"queue"<<endl; else if(!q.empty ()&&st.empty ()) cout<<"stack"<<endl; else cout<<"neither"<<endl; } return 0; }

K-Nice:这题比较有意思,在梦中我感觉好像看了解题报告,醒来之后,真的想到了对策!

#include<iostream> #include<cstdio> #include<string> using namespace std; int a[16][16]; int dir[][2]={{-1,0},{0,-1},{0,1}}; int f(int tx,int ty) { int sum=a[tx][ty]; for(int i=0;i<3;i++) { int xx=tx+dir[i][0]; int yy=ty+dir[i][1]; sum-=a[xx][yy]; } return sum; } int main() { int t,i,j; int n,m,k; cin>>t; while(t--) { cin>>n>>m>>k; if(k==(n-2)*(m-2)) { for(i=1;i<=n;i++) { for(j=1;j<m;j++) printf("%d ",0); printf("%d\n",0); } continue; } for(i=1;i<=m;i++) { a[1][i]=0;a[2][i]=0; } for(i=1;i<=n;i++) { a[i][1]=0;a[i][m]=0; } int num=0; for(i=3;i<=n;i++) { for(j=2;j<m;j++) { if(k) { k--; a[i][j]=f(i-1,j); } else { int temp=f(i-1,j); int aa=1; while(aa==temp) aa++; a[i][j]=aa; } } } for(i=1;i<=n;i++) { for(j=1;j<m;j++) printf("%d ",a[i][j]); printf("%d\n",a[i][m]); } } return 0; }

截至目前,尚未有2024年四川省级大学生程序设计竞赛的具体题目或题解公开发布。然而,可以基于以往的比赛内容推测可能涉及的类型和主题。 通常情况下,四川省大学生程序设计竞赛(Sichuan Provincial Collegiate Programming Contest)中的A题往往是一个相对基础但具有挑战性的算法问题,旨在测试参赛者的逻辑思维能力和编程技巧。例如,在2021年的比赛中,A题“Chuanpai”的核心在于通过模拟来处理周期性变化的行为模式[^3]。 对于类似的题目,解决的关键通常是识别并利用某种规律或者周期特性来进行高效计算。以下是针对该类问题的一个通用解决方案框架: ### 解决方案框架 假设未来某道A题涉及到周期行为的变化,则可以通过如下方式实现其基本逻辑: #### 周期检测与状态更新 ```python def simulate_rounds(people, preferences): rounds = 0 while not is_stable_state(people): # 判断当前状态是否稳定 update_people_based_on_preferences(people, preferences) # 更新每个人的状态 rounds += 1 return rounds, people def is_stable_state(people): # 定义稳定性条件 pass def update_people_based_on_preferences(people, preferences): n = len(preferences) new_people = [] for i in range(n): if (preferences[i] % 2 == 0 and i % 2 == 0) or \ (preferences[i] % 2 != 0 and i % 2 != 0): new_people.append(add_dish(people[i])) else: new_people.append(eat_dish(people[i])) global people people = new_people[:] def add_dish(person): person['dishes'] += 1 return person def eat_dish(person): if person['dishes'] > 0: person['dishes'] -= 1 return person ``` 上述代码片段展示了如何根据偏好列表`preferences`动态调整人员数组`people`的状态,并持续迭代直到达到某个稳定的终止条件为止。 尽管目前无法确切得知2024年度的确切考题细节,但从过往经验来看,比赛倾向于考察选手们对数据结构、算法优化以及边界情况处理的理解程度。 ### 结论 综上所述,虽然具体到2024年的赛事详情尚不可知,但是通过对历年真题的学习研究可以帮助预测可能出现的方向及其应对策略。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值