Robberies

部署运行你感兴趣的模型镜像

Robberies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4852    Accepted Submission(s): 1844


Problem Description
The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucrative business of bank robbery only for a short while, before retiring to a comfortable job at a university.


For a few months now, Roy has been assessing the security of various banks and the amount of cash they hold. He wants to make a calculated risk, and grab as much money as possible.


His mother, Ola, has decided upon a tolerable probability of getting caught. She feels that he is safe enough if the banks he robs together give a probability less than this.
 

 

Input
The first line of input gives T, the number of cases. For each scenario, the first line of input gives a floating point number P, the probability Roy needs to be below, and an integer N, the number of banks he has plans for. Then follow N lines, where line j gives an integer Mj and a floating point number Pj . 
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
 

 

Output
For each test case, output a line with the maximum number of millions he can expect to get while the probability of getting caught is less than the limit set.

Notes and Constraints
0 < T <= 100
0.0 <= P <= 1.0
0 < N <= 100
0 < Mj <= 100
0.0 <= Pj <= 1.0
A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have very low funds.
 

 

Sample Input
3
0.04 3
1 0.02
2 0.03
3 0.05
 
0.06 3
2 0.03
2 0.03
3 0.05
 
0.10 3
1 0.03
2 0.02
3 0.05
 
Sample Output
2
4
6
 
题意:Roy想要抢劫银行,每家银行多有一定的金额和被抓到的概率,知道Roy被抓的最大概率P,求Roy在被抓的情况下,抢劫最多。
分析:被抓概率可以转换成安全概率,Roy的安全概率大于1-P时都是安全的。抢劫的金额为0时,肯定是安全的,所以d[0]=1;其他金额初始为最危险的所以概率全为0;
注意:不要误以为精度只有两位。
 
复制代码
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #define MAXN 101
 5 #define MAXV 10001
 6 
 7 using namespace std;
 8 
 9 int cost[MAXN];
10 double weight[MAXV],d[MAXV];
11 
12 int main()
13 {
14     int test,sumv,n,i,j;
15     double P;
16     cin>>test;
17     while(test--)
18     {
19         scanf("%lf %d",&P,&n);
20         P=1-P;
21         sumv=0;
22         for(i=0;i<n;i++)
23         {
24             scanf("%d %lf",&cost[i],&weight[i]);
25             weight[i]=1-weight[i];
26             sumv+=cost[i];
27         }
28         for(i=0;i<=sumv;i++)
29             d[i]=0;
30         d[0]=1;
31         for(i=0;i<n;i++)
32         {
33             for(j=sumv;j>=cost[i];j--)
34             {
35                 d[j]=max(d[j],d[j-cost[i]]*weight[i]);
36             }
37         }
38         bool flag=false;
39         for(i=sumv;i>=0;i--)
40         {
41             if(d[i]-P>0.000000001)
42             {
43                 printf("%d\n",i);
44                 break;
45             }
46         }
47     }
48     return 0;
49 }

您可能感兴趣的与本文相关的镜像

Qwen-Image

Qwen-Image

图片生成
Qwen

Qwen-Image是阿里云通义千问团队于2025年8月发布的亿参数图像生成基础模型,其最大亮点是强大的复杂文本渲染和精确图像编辑能力,能够生成包含多行、段落级中英文文本的高保真图像

<think>我们正在解决一个具体的问题:在Tech.Tablesaw中创建折线图时横坐标无法正常显示。根据引用[1],我们知道Tablesaw使用Plot.ly进行可视化,并且使用构建器模式配置图表。引用[1]中给出了一个散点图的例子,并设置为折线模式,从而形成折线图。但是横坐标没有显示,这可能是配置问题。常见的横坐标不显示的原因:1.数据列类型不正确:横坐标列可能被识别为非数值或非时间类型,导致无法正确显示。2.图表配置问题:可能没有正确设置横坐标轴,或者横坐标轴被隐藏。在Tablesaw中,折线图通常使用`LinePlot`类创建。但引用[1]中提到使用`ScatterTrace`并设置`mode`为`LINE`来创建折线图,这也是一种方法。因此,我们需要检查:-横坐标列的数据类型是否正确(例如,如果是时间序列,是否使用`DateColumn`?如果是数值,是否使用`NumberColumn`?)-是否在创建图表时正确指定了横坐标和纵坐标的列?根据引用[1]的示例,在指定数据列时,使用`robberies.numberColumn("Record")`和`robberies.numberColumn("Robberies")`,这里横坐标是"Record",纵坐标是"Robberies"。如果我们自己的代码中横坐标列不是数值列,比如是字符串(类别)或日期,但被当作数值列处理,或者相反,这可能导致显示问题。另外,我们也可以考虑使用`Plot.show()`来显示图表,并检查是否有错误信息。针对横坐标不显示的解决方案:1.确保数据列类型正确:-如果横坐标是日期,应使用`DateColumn`,并在创建图表时使用`dateColumn`方法。-如果横坐标是数值,使用`NumberColumn`。-如果横坐标是字符串(类别),使用`CategoryColumn`。2.在创建图表时,明确指定横坐标和纵坐标的列。3.检查是否设置了横坐标轴的标题和显示属性(虽然默认是显示的)。4.尝试使用`LinePlot`的专用方法(如果使用折线图的话)或使用`Plot`的工具方法。以下是一个示例代码,展示如何创建一个正确的折线图(假设我们有一个包含日期和数值的表格):```javaTabletable=Table.read().csv("data.csv");DateColumndate=table.dateColumn("Date");NumberColumnvalue=table.numberColumn("Value");//使用LinePlotPlot.show(LinePlot.create("Title",table,"Date","Value"));//或者使用ScatterTrace来模拟折线图(如引用[1]的方式)ScatterTracetrace=ScatterTrace.builder(date,value).mode(ScatterTrace.Mode.LINE).build();Figurefigure=newFigure(trace);Plot.show(figure);```如果横坐标是日期类型,使用`DateColumn`非常重要。如果横坐标是其他类型,比如字符串,那么可能需要使用类别轴,这时可以考虑使用`CategoryColumn`,或者使用`ScatterTrace`并设置横坐标为字符串数组。如果按照以上步骤仍然无法显示横坐标,请检查:-图表是否被正确渲染?是否有其他错误?-横坐标轴是否被其他元素遮挡?尝试调整图表大小或布局。如果问题仍然存在,我们可以尝试显式设置横坐标轴的配置:在Plot.ly中,可以通过`Layout`设置坐标轴。Tablesaw封装了Plot.ly,因此我们可以使用`Layout`对象。例如:```javaScatterTracetrace=ScatterTrace.builder(date,value).mode(ScatterTrace.Mode.LINE).build();Layoutlayout=Layout.builder().xAxis(Axis.builder().title("Date").build()).yAxis(Axis.builder().title("Value").build()).build();Figurefigure=newFigure(layout,trace);Plot.show(figure);```这样显式设置横坐标轴标题和显示属性,可能会解决横坐标不显示的问题。总结步骤:1.确认横坐标列的数据类型,并使用正确的列类型(日期、数值或类别)。2.检查创建图表时传入的列名是否正确。3.尝试显式设置坐标轴(包括标题等)以确保坐标轴显示。4.使用`LinePlot`的专用方法或使用`ScatterTrace`构建折线图。如果问题仍然存在,请提供更多代码细节,以便进一步排查。相关问题:1.如何在Tablesaw中创建柱状图?2.Tablesaw支持哪些类型的图表?3.如何将Tablesaw图表导出为图片?4.如何设置Tablesaw图表的标题和坐标轴标签?</think> ### Tech.Tablesaw 折线图横坐标不显示的解决方案 在 Tablesaw 中使用 Plot.ly 创建折线图时,横坐标不显示通常是由数据绑定或图表配置问题导致的。以下是完整的排查和解决方案: #### 🔍 原因分析 & 解决方案 1. **数据类型不匹配** - **问题**:横坐标列包含非数值/非日期数据(如字符串),导致无法渲染坐标轴 - **解决**:确保横坐标列是 `DateColumn` 或 `NumberColumn` ```java // 检查列类型 System.out.println(robberies.column("Record").type()); // 应输出 DATE 或 NUMBER ``` 2. **数据绑定错误** - **问题**:未正确绑定横坐标列或使用 `numberColumn()` 读取类别数据 - **解决**: ```java // 正确绑定日期列(示例) DateColumn record = robberies.dateColumn("Record"); NumberColumn values = robberies.numberColumn("Robberies"); ScatterTrace trace = ScatterTrace.builder(record, values) // ⚠️ 用DateColumn作横坐标 .mode(ScatterTrace.Mode.LINE) .build(); ``` 3. **坐标轴配置缺失** - **问题**:Plot.ly 默认可能隐藏无标签的坐标轴 - **解决**:显式设置坐标轴标题 ```java Layout layout = Layout.builder() .title("抢劫案件趋势") .xAxis(Axis.builder().title("日期").build()) // 强制显示横坐标 .yAxis(Axis.builder().title("案件数量").build()) .build(); Plot.show(new Figure(layout, trace)); ``` 4. **空值/异常数据处理** - **问题**:横坐标数据含空值或格式错误 - **解决**:清理数据 ```java // 删除无效记录 robberies = robberies.dropRowsWithMissingValues("Record"); ``` #### 🛠️ 完整修复示例 ```java // 1. 准备数据 Table robberies = Table.read().csv("data.csv"); // 2. 验证列类型 DateColumn dates = robberies.dateColumn("Record"); if(dates.isEmpty()){ throw new IllegalStateException("横坐标列必须包含有效日期数据"); } // 3. 创建折线图 ScatterTrace trace = ScatterTrace.builder( dates, // 横坐标必须用DateColumn robberies.numberColumn("Robberies") ) .mode(ScatterTrace.Mode.LINE) .name("案件趋势") .build(); // 4. 强制显示坐标轴 Layout layout = Layout.builder() .xAxis(Axis.builder().title("日期").visible(true).build()) .build(); // 5. 渲染图表 Plot.show(new Figure(layout, trace)); ``` #### ⚡ 调试技巧 1. 临时改用散点图验证数据: ```java Plot.show(ScatterPlot.create("调试", robberies, "Record", "Robberies")); ``` 2. 检查数据范围: ```java System.out.println("横坐标范围: " + dates.min() + " 至 " + dates.max()); ``` 3. 使用简单数据测试: ```java // 生成测试数据 DateColumn testX = DateColumn.create("testDate"); testX.append(LocalDate.now()); NumberColumn testY = DoubleColumn.create("testY", new double[]{10}); ``` > 💡 **技术提示**:Tablesaw 0.43+ 已优化坐标轴渲染逻辑,建议升级版本解决历史兼容性问题[^1]。 📌 **关键注意**:当横坐标为日期时: - 确保日期格式统一(使用 `DateColumn` 自动转换) - 避免跨度过大(如 100 年以上)导致 Plot.ly 自动缩放隐藏刻度
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值