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 解题报告的更多相关文章

  1. Mango Weekly Training Round #6 解题报告

    比赛链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=41856#overview A.多种解法.可以dfs倒序染色,如mathlove ...

  2. Codeforces Round #300 解题报告

    呜呜周日的时候手感一直很好 代码一般都是一遍过编译一遍过样例 做CF的时候前三题也都是一遍过Pretest没想着去检查... 期间姐姐提醒说有Announcement也自信不去看 呜呜然后就FST了 ...

  3. BestCoder Round #86 解题报告

    A.Price List Sol 求和查询 Code #include<cstdio> #include<algorithm> #include<iostream> ...

  4. BestCoder Round #75 解题报告

    King's Cake [思路] 递推 公式:f(n,m)=f(max(m,n-m),min(m,n-m))+1,n>m [代码] #include<cstdio> #include ...

  5. BestCoder Round #76 解题报告

    DZY Loves Partition [思路] 贪心 [代码] #include <iostream> using namespace std; typedef long long ll ...

  6. Codeforces Global Round 1 解题报告

    A 我的方法是: #include<bits/stdc++.h> using namespace std; #define int long long typedef long long ...

  7. 浙江省队选拔 ZJOI2015 (Round 1) 解题报告

    最近莫名其妙地喜欢上了用这种格式写各省省选的全套题解= = 今年浙江省选的出题人是算法竞赛界传说级人物陈立杰,看样子他的出题风格很有特点……ABC三题难度是严格递减的,感觉如果在做第一题的时候被卡住的 ...

  8. BestCoder Round #40 解题报告

    这场是第一场没有米的BC... 大概也是想震一震那些一听说没米了就不打BC的人吧 这次的题目质量比以往高了许多 (然而我并没有打这一场BC 但是今天下午到现在做的过程中真的学到了不少知识呢 A题略水. ...

  9. Codeforces Round #302 解题报告

    感觉今天早上虽然没有睡醒但是效率还是挺高的... Pas和C++换着写... 544A. Set of Strings   You are given a string q. A sequence o ...

随机推荐

  1. PPP模式下的融资结构优化

    PPPcode{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && d ...

  2. redis3.0 集群实战1 -- 安装和配置

    本文主要是在centos7上安装和配置redis集群实战 参考: http://hot66hot.iteye.com/blog/2050676 集群教程: http://redisdoc.com/to ...

  3. [maven] 生命周期和插件

    maven生命周期和插件 生命周期 maven的生命周期有三套,互相独立.每个生命周期含有不同阶段,常用如下 clean 清理项目 pre-clean 执行清理前需要完成的工作 clean 清理上一次 ...

  4. SQL数据库基础(五)

    字符串函数: 时间日期函数: SELECT @@DATEFIRST AS '1st Day', DATEPART(dw, GETDATE()) AS 'Today' SELECT GETDATE() ...

  5. java微信开发

    所谓的微信开发就是在微信开发模式之下,对微信进行公众号和企业号的扩展开发.     如果要让你的微信公众号有更多的功能,比如菜单支持,自动的信息服务,查询,消息推送等,就必须开启微信的开发模式.进入微 ...

  6. js实现点击<li>标签弹出其索引值

    据说这是一道笔试题,以下是代码,没什么要文字叙述的,就是点击哪个<li>弹出哪个<li>的索引值即可: <html> <head> <style& ...

  7. WampServer搭建php环境可能遇到的问题

    WampServer搭建php环境可能遇到的问题 1.安装时报错,缺少 MSVCR100.dll 文件 这是因为wampServer安装时用到的vc库没有更新,要安装更新之后再进行安装,因为之前安装的 ...

  8. IOS单例

    单例就是只有一个实例. 两种常见的创建方法: 1. : static A *a = nil; + (A *)shareInstance { if (!a) a = [[self alloc] init ...

  9. Effective Java 60 Favor the use of standard exceptions

    Benefits to reuse preexisting exceptions It makes your API easier to learn and use. Programs using y ...

  10. 【故障处理】IMP-00010错误 12C的dmp文件导入11G

    [故障处理]IMP-00010错误 12C的dmp文件导入11G 1  BLOG文档结构图 2  前言部分 2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其 ...