BestCoder Round #4(Happy Three Friends-贪心)

本文介绍了一个涉及游戏策略的问题,通过合理的数字排列帮助游戏角色获得胜利。关键在于将最大的两个数分配给特定角色,并确保该角色的得分高于其他玩家。


Happy Three Friends


Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 934 Accepted Submission(s): 738


Problem Description
Dong-hao , Grandpa Shawn , Beautful-leg Mzry are good friends. One day , they want to play a game. There are 6 numbers on the table. Firstly , Dong-hao can change the order of 6 numbers. Secondly , Grandpa Shawn take the first one and the last one , sum them up as his scores. Thirdly , Beautiful-leg Mzry take any of 3 numbers from the last 4 numbers , and sum them up as his scores. Finally , if Grandpa Shawn's score is larger than Beautiful-leg Mzry's , Granpa Shawn wins! If Grandpa Shawn's score is smaller than Beautiful-leg Mzry's , Granpa Shawn loses. If the scores are equal , there is a tie. Nowadays , it's really sad that Grandpa Shawn loses his love. So Dong-hao wants him to win(not even tie). You have to tell Dong-hao whether he can achieve his goal.
Input
There is a number T shows there are T test cases below. ( T <= 50) For each test case , there are 6 numbers Ai ( 1 <= Ai <= 100 ).
Output
If Dong-hao can achieve his goal , output "Grandpa Shawn is the Winner!" If he can not , output "What a sad story!"
Sample Input
3 1 2 3 3 2 2 2 2 2 2 2 2 1 2 2 2 3 4
Sample Output
What a sad story! What a sad story! Grandpa Shawn is the Winner!
Hint
For the first test case , {3 , 1 , 2 , 2 , 2 , 3} Grandpa Shawn can take 6 at most . But Beautiful-leg Mzry can take 6 too. So there is a tie. For the second test cases , Grandpa Shawn loses. For the last one , Dong-hao can arrange the numbers as {3 , 2 , 2 , 2 , 1 , 4} , Grandpa Shawn can take 7 , but Beautiful-leg Mzry can take 6 at most. So Grandpa Shawn Wins!

直接把最大2个放外面,Beautiful-leg Mzry剩下的中再取最大的3个


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN ()
#define MAXM ()
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int a[7],t;
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	
	cin>>t;
	while (t--)
	{
		For(i,6) cin>>a[i];
		sort(a+1,a+7);
		if (a[6]+a[5]>a[4]+a[3]+a[2]) cout<<"Grandpa Shawn is the Winner!"<<endl;
		else cout<<"What a sad story!"<<endl;		
	}		
	return 0;
}




def run(self): """ 主执行函数 - 实现阻抗线路自动清理 """ job = self.JOB backup_layers = [] # ----------------------------- # 1. 备份所有阻抗层 # ----------------------------- self.ico.ClearAll() for zklay in self.zkLayerList: zkLay_bak = f&#39;{zklay}_bak&#39; self.ico.DelLayer(layer_list=[zkLay_bak]) self.ico.DispWork(zklay) self.incam.COM(f&#39;sel_copy_other, dest=layer_name, target_layer={zkLay_bak}, invert=no, dx=0, dy=0, size=0, x_anchor=0, y_anchor=0&#39;) backup_layers.append(zkLay_bak) self.ico.ClearLayer() # ----------------------------- # 2. 遍历每个 step 和每个备份层 # ----------------------------- for step in self.step_list: for zkLay_bak in backup_layers: zkLay_orig = zkLay_bak.replace(&#39;_bak&#39;, &#39;&#39;) # 原始层名 print(f"Processing {step} / {zkLay_bak}") self.ico.DispWork(job=job, stp=step, lay=zkLay_bak) # 执行线简化 self.incam.COM("rv_tab_empty,report=design2rout_rep,is_empty=yes") self.incam.COM("sel_design2rout,det_tol=25.4,con_tol=25.4,rad_tol=2.54") self.incam.COM("rv_tab_view_results_enabled,report=design2rout_rep,is_enabled=yes,serial_num=-1,all_count=-1") # 重新获取简化后的图元 features = self.ico.GetFeaturesPro(job, step, zkLay_bak) if not features: continue # 提取重合点(≥3条线共享) overlapping_points = self.find_overlapping_line_endpoints(features) if not overlapping_points: print(f"No overlapping points found in {zkLay_bak}") self.ico.ClearLayer() continue # 收集需要删除的 polyline 起点(避免重复删除) polylines_to_delete = set() # ----------------------------- # 3. 分析每个重合点 # ----------------------------- for coord, line_indices in overlapping_points.items(): x_round, y_round = coord for idx in line_indices: line = features[idx] xs, ys = round(line[&#39;xs&#39;], 6), round(line[&#39;ys&#39;], 6) xe, ye = round(line[&#39;xe&#39;], 6), round(line[&#39;ye&#39;], 6) # 判断该线是否 touch 当前重合点 if (xs, ys) != (x_round, y_round) and (xe, ye) != (x_round, y_round): continue # 不是这条线引起的重合,跳过 # 关键:在原始层判断导通性(不是 _bak 层) start_conduction = self.selectBallPad(zkLay=zkLay_orig, x=line[&#39;xs&#39;], y=line[&#39;ys&#39;]) end_conduction = self.selectBallPad(zkLay=zkLay_orig, x=line[&#39;xe&#39;], y=line[&#39;ye&#39;]) if not (start_conduction or end_conduction): # 标记这条线所属的 polyline 起点用于后续删除 polylines_to_delete.add((xs, ys)) # sel_polyline_feat 使用起点即可触发整根选择 # ----------------------------- # 4. 统一删除未导通的冗余线路 # ----------------------------- if polylines_to_delete: self.ico.DispWork(job=job, stp=step, lay=zkLay_bak) for sx, sy in polylines_to_delete: try: self.incam.COM(f"sel_polyline_feat, operation=select, x={sx}, y={sy}") except Exception as e: print(f"Failed to select polyline at ({sx}, {sy}): {e}") self.incam.COM("sel_delete") print(f"Deleted {len(polylines_to_delete)} redundant polylines in {zkLay_bak}") self.ico.ClearLayer() messageBox.showMessage(message="Y形阻抗线清理完成!", bitmap=&#39;information&#39;) sys.exit() 你的代码中 # 判断该线是否 touch 当前重合点 if (xs, ys) != (x_round, y_round) and (xe, ye) != (x_round, y_round): continue # 不是这条线引起的重合,跳过 我好像并没有这个要求?为什么写这个
最新发布
10-31
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值