A. Andryusha and Socks
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Andryusha is an orderly boy and likes to keep things in their place.

Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.

Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?

Input

The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs.

The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi.

It is guaranteed that Andryusha took exactly two socks of each pair.

Output

Print single integer — the maximum number of socks that were on the table at the same time.

Examples
input
  1. 1
    1 1
output
  1. 1
input
  1. 3
    2 1 1 3 2 3
output
  1. 2
Note

In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.

In the second example Andryusha behaved as follows:

  • Initially the table was empty, he took out a sock from pair 2 and put it on the table.
  • Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table.
  • Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe.
  • Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table.
  • Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe.
  • Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.

Thus, at most two socks were on the table at the same time.

题意:给你n对袜子 现在一只一只的放到桌子上  共2*n个数 当一双袜子同时出现在桌子时则拿走这双袜子 问桌子上最多能有多少只袜子

题解:标记  水

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <stack>
  7. #include <queue>
  8. #include <cmath>
  9. #include <map>
  10. #define ll __int64
  11. #define mod 1000000007
  12. #define dazhi 2147483647
  13. using namespace std;
  14. int n;
  15. int exm;
  16. int mp[];
  17. int main()
  18. {
  19. scanf("%d",&n);
  20. int now=;
  21. int ans=-;
  22. memset(mp,,sizeof(mp));
  23. for(int i=; i<=*n; i++)
  24. {
  25. scanf("%d",&exm);
  26. if(mp[exm]) {
  27. mp[exm]--;
  28. now--;
  29. }
  30. else {
  31. mp[exm]++;
  32. now++;
  33. }
  34. ans=max(ans,now);
  35. }
  36. printf("%d\n",ans);
  37. return ;
  38. }
B. The Meeting Place Cannot Be Changed
time limit per test

5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.

At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north.

You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate.

Input

The first line contains single integer n (2 ≤ n ≤ 60 000) — the number of friends.

The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 109) — the current coordinates of the friends, in meters.

The third line contains n integers v1, v2, ..., vn (1 ≤ vi ≤ 109) — the maximum speeds of the friends, in meters per second.

Output

Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road.

Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if  holds.

Examples
input
  1. 3
    7 1 3
    1 2 1
output
  1. 2.000000000000
input
  1. 4
    5 10 3 2
    2 3 2 4
output
  1. 1.400000000000
Note

In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.

题意:给你n个人的位置以及运动速度 (方向随意) 问最少需要多少时间能够使得所有的人到达同一个点

题解:三分 位置

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <stack>
  7. #include <queue>
  8. #include <cmath>
  9. #include <map>
  10. #define ll __int64
  11. #define mod 1000000007
  12. #define dazhi 2147483647
  13. using namespace std;
  14. int n;
  15. struct node
  16. {
  17. double x,v;
  18. }N[];
  19. double f(double t)
  20. {
  21. double maxn=;
  22. for(int i=;i<=n;i++)
  23. {
  24. double ans;
  25. ans=(abs(N[i].x-t))/N[i].v;
  26. maxn=max(ans,maxn);
  27. }
  28. return maxn;
  29. }
  30. int main()
  31. {
  32. scanf("%d",&n);
  33. for(int i=;i<=n;i++)
  34. scanf("%lf",&N[i].x);
  35. for(int i=;i<=n;i++)
  36. scanf("%lf",&N[i].v);
  37. double l=,r=,m1,m2;
  38. for(int i=;i<;i++)
  39. {
  40. m1=l+(r-l)/3.0;
  41. m2=r-(r-l)/3.0;
  42. if(0.00000001<(f(m2)-f(m1)))
  43. r=m2;
  44. else
  45. l=m1;
  46. }
  47. printf("%f\n",f(l));
  48. return ;
  49. }
C. Andryusha and Colored Balloons
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.

The park consists of n squares connected with (n - 1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored balloon at each of the squares. The baloons' colors are described by positive integers, starting from 1. In order to make the park varicolored, Andryusha wants to choose the colors in a special way. More precisely, he wants to use such colors that if ab and c are distinct squares that a and b have a direct path between them, and b and c have a direct path between them, then balloon colors on these three squares are distinct.

Andryusha wants to use as little different colors as possible. Help him to choose the colors!

Input

The first line contains single integer n (3 ≤ n ≤ 2·105) — the number of squares in the park.

Each of the next (n - 1) lines contains two integers x and y (1 ≤ x, y ≤ n) — the indices of two squares directly connected by a path.

It is guaranteed that any square is reachable from any other using the paths.

Output

In the first line print single integer k — the minimum number of colors Andryusha has to use.

In the second line print n integers, the i-th of them should be equal to the balloon color on the i-th square. Each of these numbers should be within range from 1 to k.

Examples
input
  1. 3
    2 3
    1 3
output
  1. 3
    1 3 2
input
  1. 5
    2 3
    5 3
    4 3
    1 3
output
  1. 5
    1 3 2 5 4
input
  1. 5
    2 1
    3 2
    4 3
    5 4
output
  1. 3
    1 2 3 1 2
Note

In the first sample the park consists of three squares: 1 → 3 → 2. Thus, the balloon colors have to be distinct.

Illustration for the first sample.

In the second example there are following triples of consequently connected squares:

  • 1 → 3 → 2
  • 1 → 3 → 4
  • 1 → 3 → 5
  • 2 → 3 → 4
  • 2 → 3 → 5
  • 4 → 3 → 5

We can see that each pair of squares is encountered in some triple, so all colors have to be distinct.Illustration for the second sample.

In the third example there are following triples:

  • 1 → 2 → 3
  • 2 → 3 → 4
  • 3 → 4 → 5

We can see that one or two colors is not enough, but there is an answer that uses three colors only.Illustration for the third sample.

题意:给你一颗树 现在涂色 要求连续的三个结点的颜色不能相同  问最少需要多少种颜色 并输出每个结点的颜色

题解:dfs处理

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <stack>
  7. #include <queue>
  8. #include <cmath>
  9. #include <map>
  10. #define ll __int64
  11. #define mod 1000000007
  12. #define dazhi 2147483647
  13. using namespace std;
  14. int n;
  15. struct node
  16. {
  17. int pre;
  18. int to;
  19. }N[];
  20. int pre[];
  21. int nedge=;
  22. int mp[];
  23. int re[];
  24. int ma=;
  25. void add(int p,int to)
  26. {
  27. nedge++;
  28. N[nedge].to=to;
  29. N[nedge].pre=pre[p];
  30. pre[p]=nedge;
  31. }
  32. void dfs(int root,int be1,int be2,int ans)
  33. {
  34. mp[root]=;
  35. ma=max(ma,ans);
  36. re[root]=ans;
  37. int jishu=;
  38. be2=be1;
  39. be1=ans;
  40. for(int i=pre[root];i;i=N[i].pre)
  41. {
  42. if(mp[N[i].to]==)
  43. continue;
  44. while(jishu)
  45. {
  46. if(jishu==be1||jishu==be2)
  47. jishu++;
  48. else
  49. break;
  50. }
  51. dfs(N[i].to,be1,be2,jishu);
  52. jishu++;
  53. }
  54. }
  55. int main()
  56. {
  57. memset(pre,,sizeof(pre));
  58. memset(mp,,sizeof(mp));
  59. scanf("%d",&n);
  60. int l,r;
  61. for(int i=;i<=n-;i++)
  62. {
  63. scanf("%d %d",&l,&r);
  64. add(l,r);
  65. add(r,l);
  66. }
  67. dfs(,,,);
  68. printf("%d\n",ma);
  69. for(int i=;i<=n;i++)
  70. printf("%d ",re[i]);
  71. return ;
  72. }
D. Innokenty and a Football League
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters.

Each club's full name consist of two words: the team's name and the hometown's name, for example, "DINAMO BYTECITY". Innokenty doesn't want to assign strange short names, so he wants to choose such short names for each club that:

  1. the short name is the same as three first letters of the team's name, for example, for the mentioned club it is "DIN",
  2. or, the first two letters of the short name should be the same as the first two letters of the team's name, while the third letter is the same as the first letter in the hometown's name. For the mentioned club it is "DIB".

Apart from this, there is a rule that if for some club x the second option of short name is chosen, then there should be no club, for which the first option is chosen which is the same as the first option for the club x. For example, if the above mentioned club has short name "DIB", then no club for which the first option is chosen can have short name equal to "DIN". However, it is possible that some club have short name "DIN", where "DI" are the first two letters of the team's name, and "N" is the first letter of hometown's name. Of course, no two teams can have the same short name.

Help Innokenty to choose a short name for each of the teams. If this is impossible, report that. If there are multiple answer, any of them will suit Innokenty. If for some team the two options of short name are equal, then Innokenty will formally think that only one of these options is chosen.

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of clubs in the league.

Each of the next n lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least 3 and at most 20.

Output

It it is not possible to choose short names and satisfy all constraints, print a single line "NO".

Otherwise, in the first line print "YES". Then print n lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input.

If there are multiple answers, print any of them.

Examples
input
  1. 2
    DINAMO BYTECITY
    FOOTBALL MOSCOW
output
  1. YES
    DIN
    FOO
input
  1. 2
    DINAMO BYTECITY
    DINAMO BITECITY
output
  1. NO
input
  1. 3
    PLAYFOOTBALL MOSCOW
    PLAYVOLLEYBALL SPB
    GOGO TECHNOCUP
output
  1. YES
    PLM
    PLS
    GOG
input
  1. 3
    ABC DEF
    ABC EFG
    ABD OOO
output
  1. YES
    ABD
    ABE
    ABO
Note

In the first sample Innokenty can choose first option for both clubs.

In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs.

In the third example Innokenty can choose the second options for the first two clubs, and the first option for the third club.

In the fourth example note that it is possible that the chosen short name for some club x is the same as the first option of another club yif the first options of x and y are different.

题意:给你n个队伍的名字  现在要求选择队伍名的简写 两种选择 第一种是选择第一个串的前三个字符 第二种是选择第一个串的前两个字符以及第二个串的首字符 现在要求 每个队伍的简写要唯一存在 并且不能有 某两只

队伍 对应的第一个可选择的简写相同 并且第二个可选择的简写也相同

题解:map标记处理

update: cf 数据出水了 这个是错误的..  orzzz

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <stack>
  7. #include <queue>
  8. #include <cmath>
  9. #include <map>
  10. #define ll __int64
  11. #define mod 1000000007
  12. #define dazhi 2147483647
  13. using namespace std;
  14. int n;
  15. char a[],b[];
  16. char ans[][];
  17. string str,st;
  18. char exm1[];
  19. map<string,int>mp1;
  20. map<string,int>mp2;
  21. map<string,int>mp;
  22. int main()
  23. {
  24. scanf("%d",&n);
  25. int flag=;
  26. for(int i=;i<=n;i++)
  27. {
  28. scanf("%s %s",a,b);
  29. if(flag){
  30. exm1[]=a[];exm1[]=a[];exm1[]=a[];
  31. str.append(exm1);
  32. int zha1=,zha2=;
  33. st=str;
  34. if(mp1[str]==){
  35. ans[i][]=a[];ans[i][]=a[];ans[i][]=a[];
  36. mp1[str]=;
  37. zha1=;
  38. }
  39. str.clear();
  40. exm1[]=b[];
  41. str.append(exm1);
  42. if(mp2[str]==){
  43. ans[i][]=a[];ans[i][]=a[];ans[i][]=b[];
  44. mp2[str]=;
  45. zha2=;
  46. zha1=;
  47. }
  48. if(zha1==){
  49. if(mp[st])
  50. flag=;
  51. else
  52. mp[st]=;
  53. }
  54. else{
  55. if(zha2==){
  56. if(mp[str])
  57. flag=;
  58. else
  59. mp[str]=;
  60. }
  61. }
  62. str.clear();
  63. if((zha1==&&zha2==))
  64. flag=;
  65. }
  66. }
  67. if(flag==)
  68. printf("NO\n");
  69. else{
  70. printf("YES\n");
  71. for(int i=;i<=n;i++)
  72. {
  73. cout<<ans[i]<<endl;
  74. }
  75. }
  76. return ;
  77. }

Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A模拟 B三分 C dfs D map的更多相关文章

  1. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  2. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League

    地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...

  3. 树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E

    http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取 ...

  4. 2-sat Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D

    http://codeforces.com/contest/782/problem/D 题意: 每个队有两种队名,问有没有满足以下两个条件的命名方法: ①任意两个队的名字不相同. ②若某个队 A 选用 ...

  5. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab

    地址:http://codeforces.com/contest/782/problem/E 题目: E. Underground Lab time limit per test 1 second m ...

  6. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons

    地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...

  7. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed

    地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...

  8. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A. Andryusha and Socks

    地址:http://codeforces.com/contest/782/problem/A 题目: A. Andryusha and Socks time limit per test 2 seco ...

  9. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals )D. Innokenty and a Football League(2-sat)

    D. Innokenty and a Football League time limit per test 2 seconds memory limit per test 256 megabytes ...

随机推荐

  1. 完整的正则表达式知识汇总(Python知识不断更新)

    ## 大纲: ## 一.正则概述 1.正则是什么 正则就是一套规则,或者语法 2.正则的作用 让我们判断是否符合我们的的规则,或者根据规则找到符合规则的数据 3.使用场景 可以用正则判断我们输入的邮箱 ...

  2. 关于maven项目中修改的JS不生效的解决方案

    1. 问题描述 昨天下午博主在开发学习的过程中,碰到一个修改了JS无法生效的问题,折腾我不少的时间,现将百度到的解决方案总结一下,以便下次碰到类似问题能够最快的找到解决方案 2 解决方案 2.1 方案 ...

  3. 一篇文章让你了解GC垃圾回收器

    简单了解GC垃圾回收器 了解GC之前我们首先要了解GC是要做什么的?顾名思义回收垃圾,什么是垃圾呢? GC回收的垃圾主要指的是回收堆内存中的垃圾对象. 从根对象出发,所有被引用的对象,都是存活对象 其 ...

  4. 【第四章】Shell 条件测试表达式

    shell中条件测试的三种格式: 格式1: test 条件表达式格式2: [ 条件表达式 ]格式3: [[ 条件表达式 ]] 使用test: [root@host- ~]# test -f file ...

  5. LeetCode 144 ——二叉树的前序遍历

    1. 题目 2. 解答 2.1. 递归法 定义一个存放树中数据的向量 data,从根节点开始,如果节点不为空,那么 将当前节点的数值加入到 data 中 递归得到其左子树的数据向量 temp,将 te ...

  6. Kali渗透测试工具-nslookup

    1.交互模式 终端输入nslookup进入交互模式 (1)查询A地址记录(默认) set q=a A记录简单理解将域名转换成对应的IP地址 (2)查询mail exchanger set q=mx m ...

  7. linux 文件已经删除,但是空间没有释放的原因

    监控系统报告一台服务器的空间满了,登陆后发现/tmp下有大量access_log文件,分析是Apache的日志文件很久没有清理了,确认并执行删除操作. 但是,问题来了,执行 rm /tmp/acces ...

  8. HDU 4302 Holedox Eating (线段树模拟)

    题意:一个老鼠在一条长度为L的直线上跑,吃蛋糕,老鼠只能沿直线移动.开始时没有蛋糕,老鼠的初始位置是0. 有两个操作,0 x 代表在位置x添加一个蛋糕: 1 代表老鼠想吃蛋糕.老鼠每次都会选择离自己最 ...

  9. POJ 2653 Pick-up sticks(线段判交)

    Description Stan has n sticks of various length. He throws them one at a time on the floor in a rand ...

  10. 2017秋-软件工程第四次作业(2)-结对使用TDD框架完成单元测试

    第一次接触“单元测试”这个要求,我和队友学习了一些示例后开始操作.如下展示一些建立单元测试的过程.Step1:右键单击[解决方案]->左键单击[添加(D)]->[新建项目(N)]. Ste ...