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 ...
随机推荐
- Linux Shell系列教程之(十二)Shell until循环
本文是Linux Shell系列教程的第(十二)篇,更多Linux Shell教程请看:Linux Shell系列教程 在上两篇文章Linux Shell系列教程之(十)Shell for循环和Lin ...
- 使用Jsoup解析html网页
一. JSOUP简介 在以往用java来处理解析HTML文档或者片段时,我们通常会采用htmlparser(http://htmlparser.sourceforge.net/)这个开源类库.现在 ...
- ASP.NET HttpRuntime.Cache缓存类使用总结
1.高性能文件缓存key-value存储—Redis 2.高性能文件缓存key-value存储—Memcached 备注:三篇博文结合阅读,简单理解并且使用,如果想深入学习,请多参考文章中给出的博文地 ...
- AngularJS directive 指令相关记录
.... .directive('scopeDemo',function(){ return{ template: "<div class='panel-body'>Name: ...
- WCF实战2
上一篇中,我们创建了一个简单的WCF服务,在测试的时候,我们使用VS2008自带的WCFSVCHost(WCF服务主机)发布WCF服务,以便进行测试.这种VS2008内置的WCFSVCHost只适用于 ...
- 破解 “PEDIY CrackMe 2007” 之 KeygenMe_1_by_boonz
系统 : Windows xp 程序 :KeygenMe_1_by_boonz 程序下载地址 :http://www.crackmes.de/users/boonz/keygenme_1_by_boo ...
- VS2015发布Webservice
第一步:开启IIs:在控制面板程序——>程序功能——>打开或关闭windows功能,把“Internet信息服务”下面的“FTP服务器”.“Web管理工具”.“万维网服务”全部勾上,然后点 ...
- 让 Popwindow 向上弹出
/** * 获取父控件的位置y-popwindow的高度 = 应该显示的y坐标. x这里设置为center 不刻意指定坐标 注意:控件坐标永远是 左上角坐标! * * @param parent */ ...
- C实现通用数据结构--双向链表
双向链表概述 双向链表也叫双链表,是链表的一种,它的每个数据结点中都有两个指针,分别指向直接后继next和直接前驱prev.所以,从双向链表中的任意一个结点开始,都可以很方便地访问它的前驱结点和后继结 ...
- 内置对象Clob对从数据库表中取的字符大对象CLOB类型的列值进行读取操作
package readclobDemo.bao; import java.io.IOException; import java.io.Reader; import java.sql.Clob; i ...