hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329
题意:模拟 a.
p(r)= R'/i rel(r)=(1||0) R是前n次输入有关URL的个数 R'是后n次已经输入有关URL的个数
b.

另加:输入 istringstream
#include<iostream>
#include<sstream> //istringstream 必须包含这个头文件
#include<string>
using namespace std;
int main()
{
string str="i an a boy";
istringstream is(str);
string s;
while(is>>s)
{
cout<<s<<endl;
} }

#include<iostream>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
char a[];
int r[];
map<string,int>mp[];
void init(int k)
{
istringstream str(a);
string tmp;
str>>tmp;
mp[k].clear();
while(str>>tmp)
{
r[k]++;
mp[k][tmp]=;
}
}
double get_avep(int k)
{
istringstream str(a);
string tmp;
str>>tmp;
int i=,R=;
double ansn=0.0;
while(str>>tmp)
{
i++;
if(mp[k][tmp]==)
{
R++;
ansn+=(R*1.0)/i;
}
}
ansn/=r[k]*1.0;
return ansn;
}
int main()
{
int t;
cin>>t;
while(t--)
{ memset(r,,sizeof(r));
int n,kcas=; cin>>n;
getchar(); for(int i=;i<=n;++i)
{
gets(a);
init(i);
}
double ans=0.0;
for(int i=;i<=n;++i)
{
gets(a); ans+=get_avep(i);
}
ans/=n;
cout<<"Case #"<<++kcas<<": ";
printf("%.6lf\n",ans);
}
return ;
}
hdu 4329的更多相关文章
- HDU 4329 MAP(stringstream的用法)
这个题目有点绕,但是按着他的意思写不难模拟出来.本来是一场学弟们的训练赛,我这个学长在赛场上却WA了四次都没过,三条黑线就一直在我的脑袋上挂着... 赛后开始找原因,后来发现题目看错了,1/R中的R是 ...
- HDU 4329 Contest 3
果然换个编译器就过了.总的来说,不难,不过就是处理一些空格.学习了一个新的类 istringstream可以按空格划分.然后,那条式子要理解. 式子的意义是: 找到一个串,该串在query中是第几个找 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
随机推荐
- C语言学习 第十一次作业总结
作业总结 两次的作业,都是和指针有关.从第一次的作业开始,我就多次让同学们思考这个问题:为什么要用指针,为什么在函数的形参中要使用指针.如果能够想明白这2个问题,那么同学们应该会指针的了解就差不多足够 ...
- 求n!最后一位非零数
引子:求n!末尾0的个数 n!末尾的0来源只有2,5两个质数相乘.所以只需要考察n!中包含多少个2和多少个5.然后取其较小值即为所求.即ans=min(cnt(2),cnt(5)).而转念一想,cnt ...
- java Fn键
需求分析 我想开机禁用触摸板. 方案设计 安装驱动:比较麻烦,驱动也不一定支持开机禁用触摸板. 编程实现,让一段代码开机禁用触摸板 编程实现也分好几种方法: 使用windows API禁用触摸板,这需 ...
- chrome 更新flash插件
下载下面的插件并安装 https://fpdownload.macromedia.com/pub/labs/flashruntimes/flashplayer/install_flash_player ...
- vector定义初始化
头文件 #include<vector> using std::vector; vector<T> v1; vector<T> v2(v1); vector< ...
- MYSQL批量修改表前缀与表名sql语句
修改表名 ALTER TABLE 原表名 RENAME TO 新表名; 一句SQL语句只能修改一张表 show tables; 1. SELECT CONCAT( 'ALTER TABLE ', ta ...
- 马虎将classname加到了id属性中,造成报错
今天做了一个瀑布流布局的小例子,自己在写代码的过程中一直报cannot read property 'style' of null,百度之后说是页面还没有加载完,但是我看了代码是写在window.on ...
- MapControl控件AddLayer出现错误-引发类型为“System.Windows.Forms.AxHost+InvalidActiveXStateException”的异常
出错代码: AxMapControl pMptrl = new AxMapControl(); //add data string mdbPath = string.Format("{0}\ ...
- Web Application Penetration Testing Local File Inclusion (LFI) Testing Techniques
Web Application Penetration Testing Local File Inclusion (LFI) Testing Techniques Jan 04, 2017, Vers ...
- sql 单个字段去重查询 distinc 和 group by的效率问题
sql 查询 distinc用法 distinct 和group by都需要排序,一样的结果集从执行计划的成本代价来看差距不大,但group by 还涉及到统计,所以应该需要准备工作.所以单纯从等价结 ...