A:Adjoin the Networks

One day your boss explains to you that he has a bunch of computer networks that are currently unreachable from each other, and he asks you, the cable expert's assistant, to adjoin the networks to each other using new cables. Existing cables in the network cannot be touched.

He has
asked you to use as few cables as possible, but the length of the
cables used does not matter to him, since the cables are optical and the
connectors are the expensive parts. Your boss is rather picky on cable
usage, so you know that the already existing networks have as few cables
as possible.

Due to your humongous knowledge of computer
networks, you are of course aware that the latency for an information
packet travelling across the network is proportional to the number of
hops the packet needs, where a hop is a traversal along a single cable.
And since you believe a good solution to your boss' problem may earn you
that long wanted promotion, you decide to minimise the maximum number
of hops needed between any pair of network nodes.
Input Format

On
the first line, you are given two positive integers, the number 1≤c≤105
of computers and the number 0≤l≤c−1of existing cables. Then follow lll
lines, each line consisting of two integers a and b, the two computers
the cables connect. You may assume that every computer has a unique name
between 0 and n−1.
Output Format

The maximum number of hops in the resulting network.
样例输入1

6 4
0 1
0 2
3 4
3 5

样例输出1

3

样例输入2

11 9
0 1
0 3
0 4
1 2
5 4
6 4
7 8
7 9
7 10

样例输出2

4

  首先题目的意思是整个无向图可以通过添加一些边构成强连通,但是构成强联通之后使的最长的那条边尽可能的小,因此问题就转化为了构建一颗树使得树的直径最小
注意,l可能为0,意味着,所有的点都与其他点不相连,此时只需有任意找一点作为中间点,其余点按照圆排列在周围,此时最小直径为2.l大于0意味之一定存在子联通快。
此时,每一个联通快就是一颗子树,我们可以求出子树的直径,将其半径储存,呢么找到直径最大的两颗子树,将其半径所在的点相连,其余联通快按照圆分布在周围,两个点之间添加一条边。但要注意,如果同时存在3个直径相等的最大子联通快,则需要多加一条边(与初始情况相同,至于为什么,思考一下)。

最后要与最大联通块的直径比较。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#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 esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 1044266560
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?:x<?-:;}
typedef long long ll;
typedef pair<int,int> P;
vector<int>v[];
int vis[][];
int n,m;
int dis[],a[];
int ans,_,pos;
void dfs(int u,int d,int k)
{
dis[u]=d;
if(dis[u]>ans)
{
ans=dis[u];
_=u;
}
for(auto t:v[u])
{
if(!vis[t][k])
{
vis[t][k]=;
dfs(t,d+,k);
}
}
}
bool cmp(int x,int y){
return x>y;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=,x,y;i<m;i++)
{
scanf("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
vis[x][]=;
vis[y][]=;
}
int cnt=;
pos=-;
for(int i=;i<n;i++)
{
if(!vis[i][] && vis[i][]){
ans=-;
vis[i][]=;
dfs(i,,);
ans=-;
vis[_][]=;
dfs(_,,);//求树的直径
//printf("%d\n",ans);
pos=max(ans,pos);
a[cnt++]=(ans+)>>;
}
}
sort(a,a+cnt,cmp);
if(n==)printf("0\n");
else if(n==) printf("1\n");
else if(!cnt) printf("2\n");
else if(cnt>= && a[]==a[]) printf("%d\n",max(pos,a[]+a[]+));
else printf("%d\n",max(pos,a[]+a[]+));
return ;
}

B:Bell Ringing

Method ringing is used to ring bells in churches, particularly in England. Suppose there are 6 bells that have 6 different pitches. We assign the number 1 to the bell highest in pitch, 2 to the second highest, and so on. When the 6 bells are rung in some order—each of them exactly once—it is called a row. For example, 1, 2, 3, 4, 5, 6 and 6, 3, 2, 4, 1, 5 are two different rows.

An ideal performance contains all possible rows, each played exactly once. Unfortunately, the laws of physics place a limitation on any two consecutive rows; when a bell is rung, it has considerable inertia and the ringer has only a limited ability to accelerate or retard its cycle. Therefore, the position of each bell can change by at most one between two consecutive rows.

In Figure ??, you can see the pattern of a non-ideal performance, where bells only change position by at most one.

Given nnn, the number of bells, output an ideal performance. All possible rows must be present exactly once, and the first row should be 1,2,⋯,n.

Input Format

The first and only line of input contains an integer n such that 1≤n≤8.

Output Format

Output an ideal sequence of rows, each on a separate line. The first line should contain the row 1,2,⋯,n and each two consecutive lines should be at most 1 step away from each other. Each row should occur exactly once in the output.(No extra space at the end of each line)

本题答案不唯一,符合要求的答案均正确

样例输入

2

样例输出

1 2
2 1

题目要求只有两点,要求1:要把n个数的全排列打印出来,要求2:相邻的两层数满足同一个数字的位置变化之多一个单位

比如说 1 2 3 与 1 3 2这样是符合题意的但是1 2 3 与3 1 2是不行的因为3的位置变了两个单位同理 1 2 3与2 3 1也不符合题意。

这是一到递归题,n个数的全排列可以有n-1个数的全排列里面插入第n个数得到,同时我们只要控制插入的顺序就可以保证满足要求

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#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 esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 1044266560
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?:x<?-:;}
typedef long long ll;
int a[][],n,l,r;
void solve()
{
l=r=;a[][]=;
for(int i=;i<=n;i++)
{
int len=r;
for(int j=l;j<=r;j++)
{
if((j-l)&){
for(int t=;t<i;t++)
{
len+=;
for(int k=;k<t;k++)
a[len][k]=a[j][k];
a[len][t]=i;
for(int k=t+;k<i;k++)
a[len][k]=a[j][k-];
}
}
else{
for(int t=i-;t>=;t--){
len+=;
for(int k=;k<t;k++)
a[len][k]=a[j][k];
a[len][t]=i;
for(int k=t+;k<i;k++)
a[len][k]=a[j][k-];
}
}
}
l=r+;
r=len;
}
}
int main()
{
scanf("%d",&n);
solve();
for(int i=l;i<=r;i++)
for(int j=;j<n;j++)
printf("%d%c",a[i][j],j==n-?'\n':' ');
return ;
}

C:Cryptographer's Conundrum

The walls of the corridors at the Theoretical Computer Science group (TCS) at KTH are all but covered with whiteboards. Some of the faculty members are cryptographers, and like to write cryptographic puzzles on the whiteboards. A new puzzle is added whenever someone discovers a solution to the previous one.

When Per walked in the corridor two weeks ago, he saw that the newest puzzle read "GuvfVfNGrfg". After arriving at his computer, he quickly figured out that this was a simple ROT13 encryption of "ThisIsATest".

The series of lousy puzzles continued next week, when a new puzzle read Photo by Alan Wu "VmkgdGFyIHPDpGtlcmhldGVuIHDDpSBzdMO2cnN0YSBhbGx2YXIK". This was just base64-encoded text! "Enough with these pranks", Per thought; "I'm going to show you!"

Now Per has come up with a secret plan: every day he will erase one letter of the cipher text and replace it with a different letter, so that, in the end, the whole text reads "PerPerPerPerPerPerPer". Since Per will change one letter each day, he hopes that people will not notice.

Per would like to know how many days it will take to transform a given cipher text into a text only containing his name, assuming he substitutes one letter each day. You may assume that the length of the original cipher text is a multiple of 3.

For simplicity, you can ignore the case of the letters, and instead assume that all letters are upper-case.

Input Format

The first and only line of input contains the cipher text on the whiteboard. It consists of at most 300 upper-case characters, and its length is a multiple of 3.

Output Format

Output the number of days needed to change the cipher text to a string containing only Per's name.

样例输入

SECRET

样例输出

4
签到题
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#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 esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 1044266560
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?:x<?-:;}
typedef long long ll;
char s[];
map<int,char>m;
int main()
{
m[]='P';
m[]='E';
m[]='R';
while(scanf("%s",&s)!=EOF)
{
int ans=;
for(int i=;s[i];i++)
if(s[i]!=m[i%]) ans++;
printf("%d\n",ans);
}
return ;
}

D:Disastrous Downtime

You're investigating what happened when one of your computer systems recently broke down. So far you've concluded that the system was overloaded; it looks like it couldn't handle the hailstorm of incoming requests. Since the incident, you have had ample opportunity to add more servers to your system, which would make it capable of handling more concurrent requests. However, you've simply been too lazy to do it—until now. Indeed, you shall add all the necessary servers . . . very soon!

To predict future requests to your system, you've reached out to the customers of your service, asking them for details on how they will use it in the near future. The response has been pretty impressive; your customers have sent you a list of the exact timestamp of every request they will ever make!

You have produced a list of all the nnn upcoming requests specified in milliseconds. Whenever a request comes in, it will immediately be sent to one of your servers. A request will take exactly 100010001000 milliseconds to process, and it must be processed right away.

Each server can work on at most kkk requests simultaneously. Given this limitation, can you calculate the minimum number of servers needed to prevent another system breakdown?

Input Format

The first line contains two integers 1≤n≤100000and 1≤k≤100000, the number of upcoming requests and the maximum number of requests per second that each server can handle.

Then follow nnn lines with one integer 0≤ti≤1000000each, specifying that the iii-th request will happen tit_iti​ milliseconds from the exact moment you notified your customers. The timestamps are sorted in chronological order. It is possible that several requests come in at the same time.

Output Format

Output a single integer on a single line: the minimum number of servers required to process all the incoming requests, without another system breakdown.

样例输入1

2 1
0
1000

样例输出1

1

样例输入2

3 2
1000
1010
1999

样例输出2

2
一个数可能包含在他的前1000ms或者后1000ms内
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#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 esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 1044266560
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?:x<?-:;}
typedef long long ll;
int n,m,a[];
int main()
{
scanf("%d%d",&n,&m);
for(int i=,x;i<n;i++){
scanf("%d",&x);
a[x]++;
}
int ans=;
for(int i=;i<;i++){
for(int j=i+;j<i+;j++)
a[i]+=a[j];
ans=max(ans,a[i]);
}
printf("%d\n",ans/m+(ans%m?:));
return ;
}

E:Entertainment Box

Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fights they have finally decided to buy a video tape recorder. This fabulous, new device can record kkk different TV shows simultaneously, and whenever a show recorded in one the machine's kkk slots ends, the machine is immediately ready to record another show in the same slot.

The three friends wonder how many TV shows they can record during one day. They provide you with the TV guide for today's shows, and tell you the number of shows the machine can record simultaneously. How many shows can they record, using their recording machine? Count only shows that are recorded in their entirety.
Input Format

The first line of input contains two integers n, k (1≤k<n≤100000). Then follow nnn lines, each containing two integers xi,yi, meaning that show iii starts at time xix_ixi​ and finishes by time yiy_iyi​. This means that two shows iii and jjj, where yi=xjy_i = x_jyi​=xj​, can be recorded, without conflict, in the same recording slot. You may assume that 0≤xi<yi≤10000000000.
Output Format

The output should contain exactly one line with a single integer: the maximum number of full shows from the TV guide that can be recorded with the tape recorder.
样例输入1

3 1
1 2
2 3
2 3

样例输出1

2

样例输入2

4 1
1 3
4 6
7 8
2 5

样例输出2

3

样例输入3

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

样例输出3

3

贪心问题+多重集合,每次查找可以插入的位置来更新ans,排序按照结束时间排序
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#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 esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 1044266560
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?:x<?-:;}
typedef long long ll;
multiset<int>s;
multiset<int>::iterator it;
int n,k;
struct node
{
int x,y;
bool operator<(const node &a)const{
return a.y==y?a.x<x:a.y>y;
}
}e[];
int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<n;i++)
scanf("%d%d",&e[i].x,&e[i].y);
sort(e,e+n);
for(int i=;i<k;i++)
s.insert();
int ans=;
for(int i=;i<n;i++)
{
it=s.upper_bound(e[i].x);
if(it==s.begin()) continue;
it--;
s.erase(it);
s.insert(e[i].y);
ans++;
}
printf("%d\n",ans);
return ;
}

G:Goblin Garden Guards

In an unprecedented turn of events, goblins recently launched an invasion against the Nedewsian city of Mlohkcots. Goblins—small, green critters—love nothing more than to introduce additional entropy into the calm and ordered lives of ordinary people. They fear little, but one of the few things they fear is water.

The goblin invasion has now reached the royal gardens, where the goblins are busy stealing fruit, going for joyrides on the lawnmower and carving the trees into obscene shapes, and King Lrac Fatsug has decreed that this nonsense stop immediately!

Thankfully, the garden is equipped with an automated sprinkler system. Enabling the sprinklers will soak all goblins within range, forcing them to run home and dry themselves.

Serving in the royal garden guards, you have been asked to calculate how many goblins will remain in the royal garden after the sprinklers have been turned on, so that the royal gardeners can plan their next move.
Input Format

The input starts with one integer 1≤g≤100000, the number of goblins in the royal gardens.

Then, for each goblin follows the position of the goblin as two integers, 0≤xi≤100000 and 0≤yi≤100000. The garden is flat, square and all distances are in meters. Due to quantum interference, several goblins can occupy exactly the same spot in the garden.

Then follows one integer 1≤m≤20000, the number of sprinklers in the garden.

Finally, for each sprinkler follows the location of the sprinkler as two integers 0≤xi≤100000 and 0≤yi≤100000, and the integer radius 1≤r≤100 of the area it covers,meaning that any goblin at a distance of at most rrr from the point (xi,yi) will be soaked by this sprinkler. There can be several sprinklers in the same location.
Output Format

Output the number of goblins remaining in the garden after the sprinklers have been turned on.
样例输入

5
0 0
100 0
0 100
100 100
50 50
1
0 0 50

样例输出
4

计算几何问题,所有的点都小于10000,半径不超过100,则每次可暴力枚举圆心所处的正方形内的点

但不知道怎么回事,写炸了好几次,检查不出来,看来还是代码习惯不好。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#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 esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 1044266560
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?:x<?-:;}
typedef long long ll;
int n,m;
struct Point{
int x,y;
}p[];
bool vis[][];
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
scanf("%d",&m);
for(int i=,x,y,r;i<m;i++)
{
scanf("%d%d%d",&x,&y,&r);
for(int i=max(,x-r);i<=min(,x+r);i++)
for(int j=max(,y-r);j<=min(,y+r);j++)
if(((i-x)*(i-x))+((j-y)*(j-y))<=r*r) vis[i][j]=;
}
int ans=;
for(int i=;i<n;i++)
if(!vis[p[i].x][p[i].y]) ans++;
printf("%d\n",ans);
return ;
}

Nordic Collegiate Programming Contest 2015​(第七场)的更多相关文章

  1. Nordic Collegiate Programming Contest 2015​ B. Bell Ringing

    Method ringing is used to ring bells in churches, particularly in England. Suppose there are 6 bells ...

  2. Nordic Collegiate Programming Contest 2015​ G. Goblin Garden Guards

    In an unprecedented turn of events, goblins recently launched an invasion against the Nedewsian city ...

  3. Nordic Collegiate Programming Contest 2015​ E. Entertainment Box

    Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fight ...

  4. Nordic Collegiate Programming Contest 2015​ D. Disastrous Downtime

    You're investigating what happened when one of your computer systems recently broke down. So far you ...

  5. (寒假GYM开黑)2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)

    layout: post title: 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) author: &qu ...

  6. German Collegiate Programming Contest 2015 计蒜课

    // Change of Scenery 1 #include <iostream> #include <cstdio> #include <algorithm> ...

  7. Codeforces Gym101572 B.Best Relay Team (2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017))

    2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017) 今日份的训练,题目难度4颗星,心态被打崩了,会的算法太少了,知 ...

  8. 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)- D. Delivery Delays -二分+最短路+枚举

    2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)- D. Delivery Delays -二分+最短路+枚举 ...

  9. 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp

    2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp [P ...

随机推荐

  1. javascript系列-class3.循环语句

    欢迎加入前端交流群来py: 转载请标明出处! while循环   while(循环终止条件){       }   案例     输出0~100个数字  1 . 3 .  5 不输出   输出一百数字 ...

  2. 详解JSP九个内置对象

    [JSP]☆★之详解九个内置对象       在web开发中,为方便开发者,JSP定义了一些由JSP容器实现和管理的内置对象,这些对象可以直接被开发者使用,而不需要再对其进行实例化!本文详解,JSP2 ...

  3. 移动端 input 获取焦点后弹出带enter(类似于搜索,确定,前往)键盘,以及隐藏系统键盘

    一:调出系统带回车键的键盘 在项目中经常有输入框,当输入完成后点击确定执行相应的动作.但是有些设计没有确定或者搜索按钮,这就需要调用系统键盘,点击系统键盘的确定后执行相应动作. 但是单纯的input是 ...

  4. 常用css框架 Sass/Less

    Bootstrap less/sass Sass (Syntactically Awesome Stylesheets)是一种动态样式语言,Sass语法属于缩排语法,比css比多出好些功能(如变量.嵌 ...

  5. Servlet学习(一)——Servlet的生命周期、执行过程、配置

    1.什么是Servlet Servlet 运行在服务端的Java小程序,是sun公司提供一套规范(接口),用来处理客户端请求.响应给浏览器的动态资源.但servlet的实质就是java代码,通过jav ...

  6. 路飞学城Python-Day9

    [23.函数-高阶函数]变量可以指向函数,函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就称为高阶函数如果一个函数可以接收另一个函数,这个函数就称为高阶函数 def func ...

  7. json转换方法

    import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.ut ...

  8. perl脚本去除文件中重复数据

    今天第一天写博客,写的不好请大家多多指教,废话不多说了,干货送上: ############################################################# #!/u ...

  9. .Net基础杂记

    1.面向对象程序思想 面向对象是程序开发的一种机制,特征为封装.继承.多态.以面向对象方式编写程序时,将复杂的项目抽象为多个对象互相协作的模型,然后编写模型结构,声明或实现类型的成员,即描述对象的特征 ...

  10. cobbler Ubuntu16.04 安装

    cobbler vim /etc/debmirror.conf      sed -i 's/@dists=\"sid\";/#@dists=\"sid\";/ ...