YCOJ挖地雷

挖地雷

Description

在一个地图上有N个地窖(N<=200),每个地窖中埋有一定数量的地雷。同时,给出地窖之间的连接路径,并规定路径都是单向的,也不存在可以从一个地窖出发经过若干地窖后又回到原来地窖的路径。某人可以从任一处开始挖地雷,然后沿着指出的连接往下挖(仅能选择一条路径),当无连接时挖地雷工作结束。设计一个挖地雷的方案,使他能挖到最多的地雷。
Input

第一行一个整数n表示有n个地窖
第二行有n个整数表示每个地窖的地雷数
以下有若干行,每行有两个数x,y表示x可以到y,保证x小于y。
最后一行有两个0,表示输入结束

Output

第一行输出挖地雷的顺序。

第二行为最多挖出的地雷数

Sample Input 1

6
5 10 20 5 4 5
1 2
1 4
2 4
3 4
4 5
4 6
5 6
0 0
Sample Output 1

3-4-5-6
34
——摘自YCOJ

从题目得知,这是一个有向图。
在这里插入图片描述
也就是说,1可以到2,但2一定不能到1。
在这里插入图片描述
嗯~可爱的代码:

#include<bits/stdc++.h>
using namespace std;
int b[1000][1000];
int fa[1000],mp[1000],a[1000];
int n,x,y,ans;
int mx,maxn;
int main(){
 cin&
文件里共包含有14个文件,部分代码如下: package 挖雷游戏; /** * * @author Administrator */ import java.awt.event.*; import java.awt.*; import javax.swing.*; import javax.swing.border.*; import java.util.*; import java.io.*; public class Game extends JFrame implements ActionListener { JMenuBar bar; JMenu fileMenu; JMenuItem 初级,中级,高级,扫雷英雄榜; int grade=2; MineSquare 雷阵; JButton buttonPerson; Container con; JPanel box; File 英雄榜=new File("英雄榜.txt"); Hashtable hashtable=null; Record 记录对话框=null; ShowRecord 显示英雄榜对话框=null; Game() { buttonPerson=new JButton(new ImageIcon("微笑脸.gif")); 雷阵=new MineSquare("中级",40,16,16,buttonPerson,记录对话框); buttonPerson.addActionListener(this); con=getContentPane(); con.add(雷阵,BorderLayout.CENTER); box=new JPanel(); box.setLayout(new GridLayout(1,3)); box.add(雷阵.count.textShowMine); box.add(buttonPerson); box.add(雷阵.time.textShowTime); con.add(box,BorderLayout.NORTH); setVisible(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setBounds(100,50,360,380); bar=new JMenuBar(); fileMenu=new JMenu("游戏"); 初级=new JMenuItem("初级"); 中级=new JMenuItem("中级"); 高级=new JMenuItem("高级"); fileMenu.setMnemonic('G'); 初级.setMnemonic('B'); 中级.setMnemonic('I'); 高级.setMnemonic('E'); 扫雷英雄榜=new JMenuItem("扫雷英雄榜"); 初级.setMnemonic('T'); fileMenu.add(初级); fileMenu.add(中级); fileMenu.add(高级); fileMenu.add(扫雷英雄榜); bar.add(fileMenu); setJMenuBar(bar); 初级.addActionListener(this); 中级.addActionListener(this); 高级.addActionListener(this); 扫雷英雄榜.addActionListener(this); hashtable=new Hashtable(); hashtable.put("初级","初级#"+999+"#匿名"); hashtable.put("中级","中级#"+999+"#匿名"); hashtable.put("高级","高级#"+999+"#匿名"); 记录对话框=new Record(this,hashtable); 记录对话框.setGrade("高级"); if(!英雄榜.exists()) { try{ FileOutputStream out=new FileOutputStream(英雄榜); ObjectOutputStream object_out=new ObjectOutputStream(out); object_out.writeObject(hashtable); object_out.close(); out.close(); } catch(IOException e) { } } 显示英雄榜对话框=new ShowRecord(this,hashtable); validate(); } public void newGame(String grade,int number,int rows,int cols,int w,int h) { buttonPerson.setIcon(new ImageIcon("微笑脸.gif")); 记录对话框.setGrade(grade); 雷阵=new MineSquare(grade,number,rows,cols,buttonPerson,记录对话框); con.removeAll(); box.removeAll(); box.add(雷阵.count.textShowMine); box.add(buttonPerson); box.add(雷阵.time.textShowTime); con.add(box,BorderLayout.NORTH); con.add(雷阵,BorderLayout.CENTER); setBounds(10,10,w,h); validate(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==初级) { grade=1; newGame("初级",10,8,8,180,220); } if(e.getSource()==中级) { grade=2; newGame("中级",40,16,16,360,380); } if(e.getSource()==高级) { grade=3; newGame("高级",99,22,22,500,520); } if(e.getSource()==扫雷英雄榜) { 显示英雄榜对话框.显示记录(); 显示英雄榜对话框.setVisible(true); } if(e.getSource()==buttonPerson) { if(grade==1) { newGame("初级",10,8,8,180,220); } if(grade==2) { newGame("中级",40,16,16,360,380); } if(grade==3) { newGame("高级",99,22,22,500,520); } } } public static void main(String args[]) { new Game(); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值