Nordic Collegiate Programming Contest 2015(第七场)
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
最后要与最大联通块的直径比较。
#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
#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(第七场)的更多相关文章
- 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 ...
- Nordic Collegiate Programming Contest 2015 G. Goblin Garden Guards
In an unprecedented turn of events, goblins recently launched an invasion against the Nedewsian city ...
- 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 ...
- 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 ...
- (寒假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 ...
- German Collegiate Programming Contest 2015 计蒜课
// Change of Scenery 1 #include <iostream> #include <cstdio> #include <algorithm> ...
- 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颗星,心态被打崩了,会的算法太少了,知 ...
- 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 -二分+最短路+枚举 ...
- 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 ...
随机推荐
- [TJOI2017] DNA 解题报告 (hash+二分)
题目链接:https://www.luogu.org/problemnew/show/P3763 题目大意: 给定原串S0,询问S0有多少个子串和给定串S相差不到3个字母 题解: 我们枚举S0的子串, ...
- 读书笔记-构建高性能Web站点
基本概念 带宽:通常说的带宽比如8M带宽,是指主机与互联网运营商的交换机之间的数据传输速度,因为数据链路层的流量是通过控制接收方实现的.而百兆网卡则是指网卡的发送速度为100Mbit/s,则是指网卡发 ...
- jq弹窗(获取页面宽高,滚轮高度,始终居中)
jq写一个弹窗,效果如上图所示, 点击按钮弹窗弹出,右上角关闭. 弹窗始终显示在页面中间,无论放大缩小窗口,滚轮滚动. 代码如下: html: <br><br><br&g ...
- tabIndex-bootstrap中Get到的
网页键盘的无障碍访问性 其实加了这个,可以控制Tab键切换的顺序,聚焦等 这个属性,任何标签都可以添加,没有兼容性限制,属性值的范围:0-32767 当一个元素设置tabindex属性值为-1的时候, ...
- POJ 3617 Best Cow Line 贪心算法
Best Cow Line Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26670 Accepted: 7226 De ...
- hiho 172周 - 二维树状数组模板题
题目链接 描述 You are given an N × N matrix. At the beginning every element is 0. Write a program supporti ...
- vue如何给它的data值赋值
activeDisplay的值如何改变 用$set();方法 vm.$set('b', 2) 或者 Vue.set(data, 'c', 3) this.someObject = Object.ass ...
- 3ds Max制作客厅场景实例教程
附件系列 (图01) 让我们回顾一下场景:一个房间包括下列一件件家具, 在中间的一张小桌子,在房间的角落的一个小桌子,有一个垃圾桶和一个带镜子的边桌,有一个烛台.还有一个挂钟,窗帘,沙发和带手臂的椅子 ...
- 贰、js的基础(一)
1.js的语法 a.区分大小写 b.弱类型变量:变量无特定类型 c.每行结尾的分号可有可无 d.括号用于代码块 e.注释的方法与c语言和java相同 2.变量 注意事项: a.通过关键字var来声明. ...
- BZOJ 1190 [HNOI2007]梦幻岛宝珠(背包)
1190: [HNOI2007]梦幻岛宝珠 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1385 Solved: 798[Submit][Stat ...