A.Minimum’s Revenge

There is a graph of n vertices which are indexed from 1 to n. For any pair of different vertices, the weight of the edge between them is the least common multiple of their indexes.

Mr. Frog is wondering about the total weight of the minimum spanning tree. Can you help him?

InputThe first line contains only one integer T (T≤100T≤100), which indicates the number of test cases.

For each test case, the first line contains only one integer n (2≤n≤1092≤n≤109), indicating the number of vertices. 
OutputFor each test case, output one line "Case #x:y",where x is the case number (starting from 1) and y is the total weight of the minimum spanning tree. 
Sample Input

2
2
3

Sample Output

Case #1: 2
Case #2: 5

代码:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int T,tot=;
cin>>T;
while(T--)
{
ll n;
scanf("%lld",&n);
ll ans=(n+)*n/;
ans--;
printf("Case #%d: %lld\n",++tot,ans);
} return ;
}

C.Mr. Frog’s Problem

One day, you, a clever boy, feel bored in your math class, and then fall asleep without your control. In your dream, you meet Mr. Frog, an elder man. He has a problem for you.

He gives you two positive integers A and B, and your task is to find all pairs of integers (C, D), such that A≤C≤B,A≤D≤BA≤C≤B,A≤D≤B and AB+BA≤CD+DCAB+BA≤CD+DC

Inputfirst line contains only one integer T (T≤125T≤125), which indicates the number of test cases. Each test case contains two integers A and B (1≤A≤B≤10181≤A≤B≤1018).OutputFor each test case, first output one line "Case #x:", where x is the case number (starting from 1).

Then in a new line, print an integer s indicating the number of pairs you find.

In each of the following s lines, print a pair of integers C and D. pairs should be sorted by C, and then by D in ascending order. 
Sample Input

2
10 10
9 27

Sample Output

Case #1:
1
10 10
Case #2:
2
9 27
27 9

代码:

#include <bits/stdc++.h>
using namespace std; int T;
long long A, B, C, D; int main() {
scanf("%d", &T);
for(int t = ; t <= T; t ++) {
scanf("%lld%lld", &A, &B);
printf("Case #%d:\n", t);
if(A == B) {
printf("1\n");
printf("%lld %lld\n", A, B);
} else {
printf("2\n");
printf("%lld %lld\n", A, B);
printf("%lld %lld\n", B ,A);
}
}//
return ;
}

E.Mr. Frog’s Game

One day, Mr. Frog is playing Link Game (Lian Lian Kan in Chinese).

In this game, if you can draw at most three horizontal or vertical head-and-tail-connected lines over the empty grids(the lines can be out of the whole board) to connect two non-empty grids with the same symbol or the two non-empty grids with the same symbol are adjacent, then you can change these two grids into empty and get several more seconds to continue the game.

Now, Mr. Frog starts a new game (that means there is no empty grid in the board). If there are no pair of grids that can be removed together,Mr. Frog will say ”I’m angry” and criticize you.

Mr. Frog is battle-scarred and has seen many things, so he can check the board in a very short time, maybe one second. As a Hong Kong Journalist, what you should do is to check the board more quickly than him, and then you can get out of the room before Mr. Frog being angry.

InputThe first line contains only one integer T (T≤500T≤500), which indicates the number of test cases.

For each test case, the first line contains two integers n and m (1≤n,m≤301≤n,m≤30).

In the next n lines, each line contains m integers,  j-th number in the i-th line means the symbol on the grid(the same number means the same symbol on the grid). 
OutputFor each test case, there should be one line in the output.

You should output “Case #x: y”,where x is the case number(starting from 1), and y is a string representing the answer of the question. If there are at least one pair of grids that can be removed together, the y is “Yes”(without quote), else y is “No”.Sample Input

2
3 3
1 2 1
2 1 2
1 2 1
3 3
1 2 3
2 1 2
3 2 1

Sample Output

Case #1: Yes
Case #2: No

代码:

#include <bits/stdc++.h>
using namespace std;
int a[][];
map <int,int> Map;
int main()
{
int T,tot=;
cin>>T;
while(T--)
{
Map.clear();
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
scanf("%d",&a[i][j]);
}
} int flag=;
for(int i=;i<=m;i++)
{
if(!Map[a[][i]]) Map[a[][i]]=;
else flag++;
}
if(flag)
{
printf("Case #%d: Yes\n",++tot);
continue;
}
Map.clear();
for(int i=;i<=m;i++)
{
if(!Map[a[n][i]]) Map[a[n][i]]=;
else flag++;
}
if(flag)
{
printf("Case #%d: Yes\n",++tot);
continue;
}
Map.clear();
for(int i=;i<=n;i++)
{
if(!Map[a[i][]]) Map[a[i][]]=;
else flag++;
}
if(flag)
{
printf("Case #%d: Yes\n",++tot);
continue;
}
Map.clear();
for(int i=;i<=n;i++)
{
if(!Map[a[i][m]]) Map[a[i][m]]=;
else flag++;
}
if(flag)
{
printf("Case #%d: Yes\n",++tot);
continue;
} for(int i=;i<=n;i++)
{
for(int j=;j<=m-;j++)
{
if(a[i][j]==a[i][j+])
{
flag++;
}
}
if(flag) break;
}
if(flag)
{
printf("Case #%d: Yes\n",++tot);
continue;
} for(int i=;i<=m;i++)
{
for(int j=;j<=n-;j++)
{
if(a[j][i]==a[j+][i])
{
flag++;
}
}
if(flag) break;
}
if(flag)
{
printf("Case #%d: Yes\n",++tot);
continue;
}
else
{
printf("Case #%d: No\n",++tot);
}
} return ;
}

F.Auxiliary Set

Given a rooted tree with n vertices, some of the vertices are important.

An auxiliary set is a set containing vertices satisfying at least one of the two conditions:

∙∙It is an important vertex 
∙∙It is the least common ancestor of two different important vertices.

You are given a tree with n vertices (1 is the root) and q queries.

Each query is a set of nodes which indicates the unimportant vertices in the tree. Answer the size (i.e. number of vertices) of the auxiliary set for each query. 

InputThe first line contains only one integer T (T≤1000T≤1000), which indicates the number of test cases.

For each test case, the first line contains two integers n (1≤n≤1000001≤n≤100000), q (0≤q≤1000000≤q≤100000).

In the following n -1 lines, the i-th line contains two integers ui,vi(1≤ui,vi≤n)ui,vi(1≤ui,vi≤n)indicating there is an edge between uiuii and vivi in the tree.

In the next q lines, the i-th line first comes with an integer mi(1≤mi≤100000)mi(1≤mi≤100000)indicating the number of vertices in the query set.Then comes with mi different integers, indicating the nodes in the query set.

It is guaranteed that ∑qi=1mi≤100000∑i=1qmi≤100000.

It is also guaranteed that the number of test cases in which n≥1000n≥1000  or ∑qi=1mi≥1000∑i=1qmi≥1000 is no more than 10. 
OutputFor each test case, first output one line "Case #x:", where x is the case number (starting from 1).

Then q lines follow, i-th line contains an integer indicating the size of the auxiliary set for each query. 
Sample Input

1
6 3
6 4
2 5
5 4
1 5
5 3
3 1 2 3
1 5
3 3 1 4

Sample Output

Case #1:
3
6
3

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + ;
int T;
int a[maxn];
int deep[maxn], fa[maxn], son[maxn], soon[maxn];
vector<int> v[maxn]; void dfs(int child, int parent) {
fa[child] = parent;
deep[child] = deep[parent] + ;
son[child] = ; for(int i = ; i < v[child].size(); i ++) {
if(v[child][i] != parent) {
dfs(v[child][i], child);
son[child] ++;
}
} } bool cmp(int a, int b) {
return deep[a] > deep[b];
} int main() {
scanf("%d", &T);
for(int t = ; t <= T; t ++) {
int N, M;
scanf("%d%d", &N, &M); for(int i = ; i <= N; i ++)
v[i].clear(); for(int i = ; i < N - ; i ++) {
int st, en;
scanf("%d%d", &st, &en);
v[st].push_back(en);
v[en].push_back(st);
} printf("Case #%d:\n", t);
dfs(, );
while(M --) {
int K;
scanf("%d", &K);
int ans = N - K;
for(int i = ; i < K; i ++) {
scanf("%d", &a[i]);
} sort(a, a + K, cmp); for(int i = ; i < K; i ++)
soon[a[i]] = son[a[i]]; for(int i = ; i < K; i ++) {
if(soon[a[i]] >= ) ans ++;
else if(soon[a[i]] == )
soon[fa[a[i]]] --;
} printf("%d\n", ans); } }
return ;
}

2019省赛训练组队赛3.26周二---FJUT 2016的更多相关文章

  1. 2019省赛训练组队赛3.31周四-17fj

    https://vjudge.net/contest/289558#overview A - Frog Therearex frogs and y chicken in a garden. Kim f ...

  2. hdu6578 2019湖南省赛D题Modulo Nine 经典dp

    目录 题目 解析 AC_Code @ 题目 第一题题意是一共有{0,1,2,3}四种数字供选择,问有多少个长度为n的序列满足所有m个条件,每个条件是说区间[L,R]内必须有恰好x个不同的数字. 第二题 ...

  3. QFNU-ACM 2019.5.23组队赛 2019山东省赛复现

    A.Calandar 题意:一年12个月,一个月30天,5天一周,已知某天的年月日星期数,求所给年月日的星期数是多少 思路:直接进行计算,其实每个月每年都是等长度的就使得计算的时候忽略年月,可以直接进 ...

  4. 2019牛客训练赛第七场 C Governing sand 权值线段树+贪心

    Governing sand 题意 森林里有m种树木,每种树木有一定高度,并且砍掉他要消耗一定的代价,问消耗最少多少代价可以使得森林中最高的树木大于所有树的一半 分析 复杂度分析:n 1e5种树木,并 ...

  5. X-NUCA 2017 web专题赛训练题 阳光总在风雨后和default wp

     0X0.前言 X-NUCA 2017来了,想起2016 web专题赛,题目都打不开,希望这次主办方能够搞好点吧!还没开赛,依照惯例会有赛前指导,放一些训练题让CTFer们好感受一下题目. 题目有一大 ...

  6. acm省赛选拔组队赛经验谈

    省赛组队赛已经进行5场了,过半了. 从曾经的不会组队到如今逐渐磨合,尽管每次都有遗憾,可是我认为我们一直在进步.有些失误是要记录下来下次不能再犯的! 经验: 1:上场開始一定要有人(英语能力和算法综合 ...

  7. 2019新生赛 %%%xxh

    笔记.md                                                                                                ...

  8. PTA天梯赛训练题L1-064:估值一亿的AI核心代码(字符串模拟)

    Update:smz说regex秒过Orz,yzd记在这里了. 听说今年天梯赛有个烦人的模拟,我便被队友逼着试做一下……一发15,二发20.记一记,要不然枉费我写这么久…… 自己还是代码能力太菜了,校 ...

  9. [CVPR 2019]NOCS代码训练、检测与评估

    Normalized Object Coordinate Space for Category-Level 6D Object Pose and Size Estimation 训练.检测与评估 本文 ...

随机推荐

  1. 【2018.08.13 C与C++基础】C++语言的设计与演化读书笔记

    先占坑 老实说看这本书的时候,有很多地方都很迷糊,但却说不清楚问题到底在哪里,只能和Effective C++联系起来,更深层次的东西就想不到了. 链接: https://blog.csdn.net/ ...

  2. Unity Shader 基础(2) Image Effect

    Unity中 Image Effect 是Post Processing的一种方,Unity自身也提供很多Effect效果供使用.Image Effect的使用官方文档做了很多介绍,这里重点Post ...

  3. 一张有料的图片!!!附文件-图片合成器C语言实现算法

    凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 1.打开F盘,先找两个文件,一个是压缩文件(2.rar),另一个是一张图片(1.jpg),将其放到F盘目录下, ...

  4. 《Java大学教程》—第20章 文件处理

    记录():一个单独的数据实例.域():一个属性. 20.3    输入和输出设备:P484输入过程和输出过程.操作系统负责建立三个流(stream):标准输入流(System.in).标准输出流(Sy ...

  5. 使用selenium时,使用从系统启动浏览器与通过自动化驱动方式启动浏览器控件ID不一样解决方法

    最近遇到一个怪事,通过正常打开浏览器,按照正常的web登录然后点击进入系统流程,将各控件的ID识别成功,然后使用 python3+selenium写好脚本,高高兴兴的用脚本跑时老是提示找不到控件,然后 ...

  6. vue源码分析—数据绑定

    放进沙里附件拉萨就发牢骚:剑飞:啊撒

  7. 连接rabbitmq

    #消费者import pika # 连接服务器 credentials = pika.PlainCredentials('*****', '***') connection = pika.Blocki ...

  8. [小米 Online Judge]找出单独出现的数字

    描述: 给出N个数字.其中仅有一个数字出现过一次,其他数字均出现过两次,找出这个出现且只出现过一次的数字.要求时间和空间复杂度最小. 输入: 输入多个数字,每个数字以空格分开,回车结束 输出: 输出内 ...

  9. [matlab] 12.Optimization Tool的使用

    1.quadprog 二次规划的函数 Matlab 中二次规划的数学模型可表述如下 其中 H是把目标函数二次项部分进行实对称矩阵, f是线性函数的列向量. 例求解二次规划 得到 h=[4,-4;-4, ...

  10. PHP删除数组中空值的方法介绍

    这篇文章主要介绍了PHP删除数组中空值的方法介绍,需要的朋友可以参考下 说来惭愧,以前在去掉数组的空值是都是强写foreach或者while的,利用这两个语法结构来删除数组中的空元素,简单代码如下: ...