B - Two Switches


Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

Alice and Bob are controlling a robot. They each have one switch that controls the robot.
Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.
Bob started holding down his button C second after the start-up, and released his button D second after the start-up.
For how many seconds both Alice and Bob were holding down their buttons?

Constraints

  • 0≤A<B≤100
  • 0≤C<D≤100
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.


Sample Input 1

Copy
0 75 25 100

Sample Output 1

Copy
50

Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.
Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.
Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.


Sample Input 2

Copy
0 33 66 99

Sample Output 2

Copy
0

Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.


Sample Input 3

Copy
10 90 20 80

Sample Output 3

Copy
60

求Alice和Bob操作的公共时长
    #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int a,b,c,d;
int main()
{
while(cin>>a>>b>>c>>d)
{
int ans=;
for(int i=;i<=;i++)
{
if((i>=a && i<=b) && (i>=c && i<=d))ans++;
}
printf("%d\n",ans->=?ans-:);
}
return ;
}

C - Multiple Clocks


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

We have N clocks. The hand of the i-th clock (1≤iN) rotates through 360° in exactly Ti seconds.
Initially, the hand of every clock stands still, pointing directly upward.
Now, Dolphin starts all the clocks simultaneously.
In how many seconds will the hand of every clock point directly upward again?

Constraints

  • 1≤N≤100
  • 1≤Ti≤1018
  • All input values are integers.
  • The correct answer is at most 1018 seconds.

Input

Input is given from Standard Input in the following format:

N
T1
:
TN

Output

Print the number of seconds after which the hand of every clock point directly upward again.


Sample Input 1

Copy
2
2
3

Sample Output 1

Copy
6

We have two clocks. The time when the hand of each clock points upward is as follows:

  • Clock 1: 2, 4, 6, seconds after the beginning
  • Clock 2: 3, 6, 9, seconds after the beginning

Therefore, it takes 6 seconds until the hands of both clocks point directly upward.


Sample Input 2

Copy
5
2
5
10
1000000000000000000
1000000000000000000

Sample Output 2

Copy
1000000000000000000
求n个数的最小公倍数
    #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll n,front,last;
ll gcd(ll x,ll y)
{
return y==?x:gcd(y,x%y);
}
ll lcm(ll x,ll y)
{
return x/gcd(x,y)*y;
}
int main()
{
while(scanf("%lld",&n)!=EOF)
{
scanf("%lld",&front);
for(int i=;i<n;i++)
{
scanf("%lld",&last);
front=lcm(front,last);
}
printf("%lld\n",front);
}
return ;
}

D - Transit Tree Path


Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

You are given a tree with N vertices.
Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N−1 edges, where N is the number of its vertices.
The i-th edge (1≤iN−1) connects Vertices ai and bi, and has a length of ci.

You are also given Q queries and an integer K. In the j-th query (1≤jQ):

  • find the length of the shortest path from Vertex xj and Vertex yj via Vertex K.

Constraints

  • 3≤N≤105
  • 1≤ai,biN(1≤iN−1)
  • 1≤ci≤109(1≤iN−1)
  • The given graph is a tree.
  • 1≤Q≤105
  • 1≤KN
  • 1≤xj,yjN(1≤jQ)
  • xjyj(1≤jQ)
  • xjK,yjK(1≤jQ)

Input

Input is given from Standard Input in the following format:

N
a1 b1 c1
:
aN−1 bN−1 cN−1
Q K
x1 y1
:
xQ yQ

Output

Print the responses to the queries in Q lines.
In the j-th line j(1≤jQ), print the response to the j-th query.


Sample Input 1

Copy
5
1 2 1
1 3 1
2 4 1
3 5 1
3 1
2 4
2 3
4 5

Sample Output 1

Copy
3
2
4

The shortest paths for the three queries are as follows:

  • Query 1: Vertex 2 → Vertex 1 → Vertex 2 → Vertex 4 : Length 1+1+1=3
  • Query 2: Vertex 2 → Vertex 1 → Vertex 3 : Length 1+1=2
  • Query 3: Vertex 4 → Vertex 2 → Vertex 1 → Vertex 3 → Vertex 5 : Length 1+1+1+1=4

Sample Input 2

Copy
7
1 2 1
1 3 3
1 4 5
1 5 7
1 6 9
1 7 11
3 2
1 3
4 5
6 7

Sample Output 2

Copy
5
14
22

The path for each query must pass Vertex K=2.


Sample Input 3

Copy
10
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
5 6 1000000000
6 7 1000000000
7 8 1000000000
8 9 1000000000
9 10 1000000000
1 1
9 10

Sample Output 3

Copy
17000000000

n个顶点,n-1条边,所以不存在最优路径,那么只需要从给定k顶点开始dfs就可以了
    #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
vector<pair<int,int> >v[];
ll dis[];
int n,k,x,y,w,q;
bool vis[];
void dfs(int x)
{
vis[x]=;
for(int i=;i<v[x].size();i++)
{
if(!vis[v[x][i].first])
{
dis[v[x][i].first]=dis[x]+v[x][i].second;
dfs(v[x][i].first);
}
}
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(vis,,sizeof(vis));
memset(dis,,sizeof(dis));
for(int i=;i<=n;i++)
v[i].clear();
for(int i=;i<n-;i++)
{
scanf("%d%d%d",&x,&y,&w);
v[x].push_back(make_pair(y,w));
v[y].push_back(make_pair(x,w));
}
scanf("%d%d",&q,&k);
dfs(k);
while(q--)
{
scanf("%d%d",&x,&y);
printf("%lld\n",dis[x]+dis[y]);
}
}
return ;
}

Atcoder ABC 070 B、C、D的更多相关文章

  1. 设a、b、c均是0到9之间的数字,abc、bcc是两个三位数,且有:abc+bcc=532。求满足条件的所有a、b、c的值。

    题目描述 设a.b.c均是0到9之间的数字,abc.bcc是两个三位数,且有:abc+bcc=532.求满足条件的所有a.b.c的值. 输入描述: 题目没有任何输入. 输出描述: 请输出所有满足题目条 ...

  2. 用js写已知abc+cba = 1333,其中a、b、c均为一位数,编程求出满足条件的a、b、c所有组合。

    <!--<script type="text/javascript"> //已知abc+cba = 1333,其中a.b.c均为一位数,编程求出满足条件的a.b. ...

  3. C语言 aabbcc、abc、fabc、aabc

    输入一个字符串,匹配字符串中连续出现的字符串.并且连续个数相等 如输入 aabbcc.abc.fabc.aabc.aabbc 分别输出yes还是no #include<stdio.h>#i ...

  4. 学习 JavaScript (三)核心概念:语法、变量、数据类型

    JavaScript 的核心概念主要由语法.变量.数据类型.操作符.语句.函数组成,这篇文章主要讲解的是前面三个,后面三个下一篇文章再讲解. 01 语法 熟悉 JavaScript 历史的人应该都知道 ...

  5. javascript (JS组成、书写位置、基本概念、作用域、内存问题、变量)

    1 JavaScript的组成和书写位置 Javascript:运行在客户端(浏览器)的脚本语言,JavaScript的解释器被称为JavaScript引擎,为浏览器的一部分,与java没有直接的关系 ...

  6. AtCoder ABC 250 总结

    AtCoder ABC 250 总结 总体 连续若干次一样的结果:30min 切前 4 题,剩下卡在 T5 这几次卡在 T5 都是一次比一次接近, 什么 dp 前缀和打挂,精度被卡,能水过的题连水法都 ...

  7. JavaScript学习笔记(三)——this、原型、javascript面向对象

    一.this 在JavaScript中this表示:谁调用它,this就是谁. JavaScript是由对象组成的,一切皆为对象,万物皆为对象.this是一个动态的对象,根据调用的对象不同而发生变化, ...

  8. JavaScript学习总结(三)——this、原型、javascript面向对象

    一.this 在JavaScript中this表示:谁调用它,this就是谁. JavaScript是由对象组成的,一切皆为对象,万物皆为对象.this是一个动态的对象,根据调用的对象不同而发生变化, ...

  9. JavaScript学习总结(二)——闭包、IIFE、apply、函数与对象

    一.闭包(Closure) 1.1.闭包相关的问题 请在页面中放10个div,每个div中放入字母a-j,当点击每一个div时显示索引号,如第1个div显示0,第10个显示9:方法:找到所有的div, ...

随机推荐

  1. softwares我的软件列表(转载)

    [TOC] 个人在archlinux下的日常使用经验列出,故而在archlinux及其衍生发行版中,以下所列软件几乎可以从archlinux官方源或者aur中搜索下载安装,所列出名字一般即是其包名,使 ...

  2. python2中打印列表与字典内的中文字符

    在开发过程中,我们经常需要打印一些变量的值,便于调试.这个时候就会发现如果在列表与字典这些容器中,如果包含中文字符,不管是str类型,还是unicode类型,都打印不出来.如下: >>&g ...

  3. python的模块导入机制

    在python中用import或者from...import来导入相应的模块. 模块(Module)其实就是一些函数和类的集合文件,它能实现一些相应的功能,当我们需要使用这些功能的时候,直接把相应的模 ...

  4. Git强制覆盖master分支

    在开发中,通常会保持两个分支master分支和develop分支,但是如果因为develop上面迭代太多而没有及时维护master,最后想丢弃master而直接将测试确认过的develop强推到mas ...

  5. PKU 2288 Islands and Bridges 状态dp

    题意: 给你一张地图,上面有一些岛和桥.你要求出最大的三角哈密顿路径,以及他们的数量. 哈密顿路:一条经过所有岛的路径,每个岛只经过一次. 最大三角哈密顿路:满足价值最大的哈密顿路. 价值计算分为以下 ...

  6. ArcGIS 空间查询

    public static bool QueryMessPoint(IActiveView activeView, IFeatureClass featureClass, string whereCl ...

  7. File的getPath()和getAbsolutePath()和getCanonicalPath()的差别

    这几个方法是有一次无意的发现,我当时也不知道什么意思,就百度了,查到了一些列子: 原文地址http://www.blogjava.net/dreamstone/archive/2007/08/08/1 ...

  8. UE4的JSON读写方式&lt;一&gt;

    声明:全部权利保留. 转载必须说明出处:http://blog.csdn.net/cartzhang/article/details/41009343 UE4的Json的解析博客地址: http:// ...

  9. IDEA创建maven项目之后无法编写java类

    在创建Maven web项目之后无法再java文件夹下面创建java类,这里我可以教一下大家 选择你的文件夹,鼠标点击右键,出现下图所显示的,你可以按照下图所显示的步骤进行操作

  10. Redis封装之Set

    RedisSetService: /// <summary> /// Set:用哈希表来保持字符串的唯一性,没有先后顺序,存储一些集合性的数据 /// 1.共同好友.二度好友 /// 2. ...