Mango Weekly Training Round #3 解题报告
A. Codeforces 92A Chips
签到题。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 10007 int a[]; int main()
{
int n,m,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=;i<=n;i++)
a[i] = i;
i = ;
while()
{
if(m>=a[i])
m-=a[i];
else
break;
i++;
if(i == n+)
i = ;
}
cout<<m<<endl;
}
return ;
}
B.Codeforces 217A Ice Skating
dfs或者并查集。
dfs:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 107 struct node
{
int x,y;
}a[N];
int vis[N];
int n; void joint(int k)
{
if(!vis[k])
{
vis[k] = ;
for(int i=;i<n;i++)
{
if(i != k && (a[k].x == a[i].x || a[k].y == a[i].y))
joint(i);
}
}
} int main()
{
int i;
while(scanf("%d",&n)!=EOF)
{
for(i=;i<n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
memset(vis,,sizeof(vis));
int cnt = ;
for(i=;i<n;i++)
{
if(!vis[i])
{
cnt++;
joint(i);
}
}
cout<<cnt-<<endl;
}
return ;
}
C.UVA 12592 Slogan Learning of Princess
hash,用map做就可以了,也可以用字符串数组
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
#define N 10007 map<string,string> mp; int main()
{
int n,i,q;
string s1,s2;
while(scanf("%d",&n)!=EOF)
{
getchar();
for(i=;i<n;i++)
{
getline(cin,s1);
cin.clear();
getline(cin,s2);
cin.clear();
mp[s1] = s2;
}
scanf("%d",&q);
getchar();
while(q--)
{
getline(cin,s1);
cout<<mp[s1]<<endl;
}
}
return ;
}
D.HDU 4027 Can you answer these queries?
线段树,单点更新,用一个标记表示区间内是否全为1,全为1则不用更新,以节省操作时间。注意:要用_int64类型,不要忘记每组数据后打一个空行
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define lll __int64
using namespace std;
#define N 100007 struct node
{
lll sum;
int mark;
}tree[*N]; void pushup(int rt)
{
tree[rt].sum = tree[*rt].sum + tree[*rt+].sum;
tree[rt].mark = tree[*rt].mark && tree[*rt+].mark;
} void build(int l,int r,int rt)
{
tree[rt].mark = ;
if(l == r)
{
scanf("%I64d",&tree[rt].sum);
if(tree[rt].sum == )
tree[rt].mark = ;
return;
}
int mid = (l+r)/;
build(l,mid,*rt);
build(mid+,r,*rt+);
pushup(rt);
} void update(int l,int r,int aa,int bb,int rt)
{
if(aa<=l && bb>=r)
{
if(tree[rt].mark)
return;
if(!tree[rt].mark && l == r)
{
tree[rt].sum = (lll)sqrt(tree[rt].sum);
if(tree[rt].sum <= )
tree[rt].mark = ;
return;
}
}
int mid = (l+r)/;
if(aa<=mid)
update(l,mid,aa,bb,*rt);
if(bb>mid)
update(mid+,r,aa,bb,*rt+);
pushup(rt);
} lll query(int l,int r,int aa,int bb,int rt)
{
if(aa>r || bb<l)
return ;
if(aa<=l && bb>=r)
return tree[rt].sum;
int mid = (l+r)/;
return query(l,mid,aa,bb,*rt)+query(mid+,r,aa,bb,*rt+);
} int main()
{
int n,i,q,op,aa,bb,cs = ;
while(scanf("%d",&n)!=EOF)
{
build(,n,);
scanf("%d",&q);
printf("Case #%d:\n",cs++);
while(q--)
{
scanf("%d%d%d",&op,&aa,&bb);
if(aa>bb)
swap(aa,bb);
if(op)
printf("%I64d\n",query(,n,aa,bb,));
else
update(,n,aa,bb,);
}
printf("\n");
}
return ;
}
E.UVA 11488 Hyper Prefix Sets
字典树,结构node维护两个值: count 和 deep ,结果即为节点的count * deep 的最大值。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 50007 struct node
{
int count,deep;
node *next[];
}*root; char ss[N];
int maxi; node *create()
{
node *p;
p = (node *)malloc(sizeof(node));
p->count = ;
p->deep = ;
for(int i=;i<;i++)
p->next[i] = NULL;
return p;
} void release(node *p)
{
for(int i=;i<;i++)
{
if(p->next[i] != NULL)
release(p->next[i]);
}
free(p);
} void insert(char *ss)
{
node *p = root;
int i = ,k;
while(ss[i])
{
k = ss[i++] - '';
if(p->next[k] == NULL)
p->next[k] = create();
p->next[k]->deep = p->deep + ;
p = p->next[k];
p->count++;
maxi = max(maxi,p->count*p->deep);
}
} int main()
{
int t,n,i;
scanf("%d",&t);
while(t--)
{
root = create();
scanf("%d",&n);
maxi = -;
for(i=;i<n;i++)
{
scanf("%s",ss);
insert(ss);
}
cout<<maxi<<endl;
release(root);
}
return ;
}
F.UVALive 6655 Two Points Revisited
构造法。
Mango Weekly Training Round #3 解题报告的更多相关文章
- Mango Weekly Training Round #6 解题报告
比赛链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=41856#overview A.多种解法.可以dfs倒序染色,如mathlove ...
- Codeforces Round #300 解题报告
呜呜周日的时候手感一直很好 代码一般都是一遍过编译一遍过样例 做CF的时候前三题也都是一遍过Pretest没想着去检查... 期间姐姐提醒说有Announcement也自信不去看 呜呜然后就FST了 ...
- BestCoder Round #86 解题报告
A.Price List Sol 求和查询 Code #include<cstdio> #include<algorithm> #include<iostream> ...
- BestCoder Round #75 解题报告
King's Cake [思路] 递推 公式:f(n,m)=f(max(m,n-m),min(m,n-m))+1,n>m [代码] #include<cstdio> #include ...
- BestCoder Round #76 解题报告
DZY Loves Partition [思路] 贪心 [代码] #include <iostream> using namespace std; typedef long long ll ...
- Codeforces Global Round 1 解题报告
A 我的方法是: #include<bits/stdc++.h> using namespace std; #define int long long typedef long long ...
- 浙江省队选拔 ZJOI2015 (Round 1) 解题报告
最近莫名其妙地喜欢上了用这种格式写各省省选的全套题解= = 今年浙江省选的出题人是算法竞赛界传说级人物陈立杰,看样子他的出题风格很有特点……ABC三题难度是严格递减的,感觉如果在做第一题的时候被卡住的 ...
- BestCoder Round #40 解题报告
这场是第一场没有米的BC... 大概也是想震一震那些一听说没米了就不打BC的人吧 这次的题目质量比以往高了许多 (然而我并没有打这一场BC 但是今天下午到现在做的过程中真的学到了不少知识呢 A题略水. ...
- Codeforces Round #302 解题报告
感觉今天早上虽然没有睡醒但是效率还是挺高的... Pas和C++换着写... 544A. Set of Strings You are given a string q. A sequence o ...
随机推荐
- Jaxb解析xml准换为javabean
先说下这个的背景吧,前些日子,有个以前的小同事说刚接触webservice,想解析下xml,记得我学的时候还是dom4j,sax的解析方式,最近看别人的代码用的jaxb的方式,觉得注解起来很简练,所以 ...
- 可怜的js居然没有块级作用域
js中在一个函数中定义一个for循环:for(var i=0;i<5;i++) 其中的i并不会随着for循环的结束就销毁,i会一直存在该函数中,这就是js和其他语言的区别,也就是js没有块级作用 ...
- gulp入坑系列(3)——创建多个gulp.task
继续gulp的爬坑路,在准备get更多gulp的具体操作之前,先来明确一下在gulp中创建和使用多个task任务的情况. gulp所要做的操作都写在gulp.task()中,系统有一个默认的defau ...
- jQuery.makeArray() 函数详解
jQuery.makeArray()函数用于将一个类数组对象转换为真正的数组对象. 所谓"类数组对象"就是一个常规的Object对象,但它和数组对象非常相似:具备length属性, ...
- C# DevExpress 的gridControl或gridView数据导出失败解决方法
来自:http://blog.csdn.net/lybwwp/article/details/8049464 谢谢 在使用DevExpress 的GridPanel控件的时候出现了一个莫名其妙的现象, ...
- UITabBar,UINavigationBar的布局和隐藏问题
---恢复内容开始--- 1. 前言 UITabBar,UINavigationBar非常的好用,但是毕竟是系统自带的,不受自己完全掌握,对于布局和隐藏会有一些问题,现在就来谈谈我的想法和一些问题. ...
- C语言可变参数函数实现原理
一.可变参数函数实现原理 C函数调用的栈结构: 可变参数函数的实现与函数调用的栈结构密切相关,正常情况下C的函数参数入栈规则为__stdcall, 它是从右到左的,即函数中的最右边的参数最先入栈. 本 ...
- android拍照选择图片上传服务器自定义控件
做android项目的时候总免不了遇到图片上传功能,虽然就是调用android系统的拍照和相册选择功能,但是总面部了把一大推代码写在activity里,看上去一大推代码头都昏了.不如把这些功能都集成一 ...
- setSupportActionBar(toolbar)导致程序崩溃闪退
最近在做一个项目,使用了第三方的开源项目,主要是想实现android5.0之后推出的MaterialDesign的风格,但是代码已经写好了,发现一运行就闪退,所以就开始debug,发现问题出现在 To ...
- OpenGL ES学习笔记(三)——纹理
首先申明下,本文为笔者学习<OpenGL ES应用开发实践指南(Android卷)>的笔记,涉及的代码均出自原书,如有需要,请到原书指定源码地址下载. <OpenGL ES学习笔记( ...