A. The New Year: Meeting Friends


 #include <set>
 #include <map>
 #include <stack>
 #include <queue>
 #include <cstdio>
 #include <vector>
 #include <cstring>
 #include <iostream>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
 #define mem(x,y) memset(x, y, sizeof(x))
 #define lson l,m,rt << 1
 #define rson m+1,r,rt << 1 | 1
  ? a : gcd(b, a % b);}
 int lcm(int a, int b){return a / gcd(a, b) * b;}

 int main()
 {
     ];
     scanf(], &a[], &a[]);
     sort(a, a + );
     printf(] - a[]);
     ;
 }

B - Text Document Analysis

题意:此题是一道字符串题目,统计括号内的单词个数以及括号外最长的单词长度。

字符串的题目漏了考虑'\n'的结尾!!!

 #include <set>
 #include <map>
 #include <stack>
 #include <queue>
 #include <cstdio>
 #include <vector>
 #include <cstring>
 #include <iostream>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
 #define mem(x,y) memset(x, y, sizeof(x))
 #define lson l,m,rt << 1
 #define rson m+1,r,rt << 1 | 1
  ? a : gcd(b, a % b);}
 int lcm(int a, int b){return a / gcd(a, b) * b;}

 ];
 int main()
 {
     int len;
     scanf("%d", &len);
     scanf("%s", s);
     , len_in = , len_out = , num_in =  ,len_max = ;
     ; i < len; i++)
     {
         if(s[i] == '(')
         {
             flag1 = ;
             len_max = max(len_max, len_out);
             len_out = ;
             continue;
         }
         if(flag1)
         {
             if((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z') )
                 len_in++;
             else if(s[i] == '_')
             {
                 if(len_in) num_in++;
                 len_in = ;
             }
             else if(s[i] == ')')
             {
                 flag1 = ;
                 if(len_in) num_in++;
                 len_in = ;
             }
         }
         else
         {
             if((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z') )
                 len_out++;
             else if(s[i] == '_')
             {
                 len_max = max(len_max, len_out);
                 len_out = ;
             }
         }
     }
     len_max = max(len_max, len_out);
     printf("%d %d\n", len_max, num_in);
     ;
 }

其实写复杂了,hhhhh。别人的

#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;

int main()
{
    ,len=,max=,num=;
    ];
    scanf("%d",&n);
    scanf("%s",ch);
    ;i==||ch[i-]!='\0';i++)
    {
        if(ch[i]=='_'||ch[i]=='('||ch[i]==')'||ch[i]=='\0')
        {
            &&max<len)
            {
                max=len;
            }
            &&len!=)
            {
                num++;
            }
            len=;
            if(ch[i]=='(')
            {
                flag=;
            }
            else if(ch[i]==')')
            {
                flag=;
            }
        }
        else
        {
            len++;
        }
    }
    printf("%d %d",max,num);
    ;
}

C - Polycarp at the Radio

这题意太迷了。读不懂。

D - Lakes in Berland

题意:n*m的图里,‘.’为湖,‘*’为陆地,'.'在边界的是与大海相连(即不为湖),上下左右相连的为同一个湖或者同一片海,现在要求只留下k个湖,问要最少填多少个格子。

直接贪心+dfs就A了。

 #include <set>
 #include <map>
 #include <stack>
 #include <queue>
 #include <cstdio>
 #include <vector>
 #include <cstring>
 #include <iostream>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
 #define mem(x,y) memset(x, y, sizeof(x))
 #define lson l,m,rt << 1
 #define rson m+1,r,rt << 1 | 1
  ? a : gcd(b, a % b);}
 int lcm(int a, int b){return a / gcd(a, b) * b;}

 int n, m, k, ans, flag;
 ][];
 ][];
 , , , -};
 , -, , };
 #define judge(x, y) 0 <= x && x < n && 0 <= y && y < m && vis[x][y] == 0

 struct node
 {
     int x, y, s;
     node(int xx, int yy, int ss){x = xx, y = yy, s = ss;}
     bool operator < (const node& other)const
     {
         return s > other.s;
     }
 };
 int dfs(int x, int y, int id)
 {
     ;
     ;
     vis[x][y] = ;
      || x == n -  || y ==  || y == m - ) flag = ;
      && ma[x][y] == '.')
     {
         ma[x][y] = '*', ans++;
     }

     ; i < ; i++)
     {
         int fx = x + dx[i], fy = y + dy[i];
         if(judge(fx, fy) && ma[fx][fy] == '.')
         {
             s += dfs(fx, fy, id);
         }
     }
     return s;
 }

 int main()
 {
     scanf("%d%d%d", &n, &m, &k);
     ; i < n; i++)
     {
         scanf("%s", ma[i]);
     }
     priority_queue<node>que;
     ; i < n; i++)
     {
         ; j < m; j++)
         {
              && ma[i][j] == '.')
             {
                 flag = ;
                 );
                 if(t && flag)   que.push(node(i, j, t));
             }

         }
     }
     mem(vis, );
     ans = ;

     while(que.size() > k)
     {
         node cur = que.top();que.pop();
         dfs(cur.x, cur.y, );
     }

     printf("%d\n", ans);
     ; i < n; i++)
         printf("%s\n", ma[i]);
     ;
 }

E. One-Way Reform(欧拉路径)

题意:
给你一个n个点m条边的无向连通图,没有自环没有重边(图论题一定一定要记得考虑有没有自环和重边) ,然后让你给每条边规定方向,希望使得尽可能多的点拥有相同的入度与出度,让你输出满足这个条件的最大点数和每条边最后的定向。

题解:你想吧,一个连通图,如果存在奇数的度数的顶点,那么它的个数一定是偶数个,因为你想啊,连通图吧,度数=边数*2肯定是偶数,对吧。所以奇数度的顶点也一定是偶数个。那么把所有度数为奇数的顶点和一个新增顶点相连,则图上所有顶点的度数就都是偶数了,构成欧拉图,然后欧拉路径。ans数组记录路径。

 #include <set>
 #include <map>
 #include <stack>
 #include <queue>
 #include <cstdio>
 #include <vector>
 #include <cstring>
 #include <iostream>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
 #define mem(x,y) memset(x, y, sizeof(x))
 #define lson l,m,rt << 1
 #define rson m+1,r,rt << 1 | 1
  ? a : gcd(b, a % b);}
 int lcm(int a, int b){return a / gcd(a, b) * b;}

 int T, V, E;
  + ;
 set<int>s[maxn_v];
 vector<pair<int, int> >ans;
 void init()
 {
     ; i <= V; i++)
         s[i].clear();
     ans.clear();
 }
 void dfs(int u)
 {
     while(s[u].size())
     {
         int v = *s[u].begin();
         s[u].erase(v);
         s[v].erase(u);
         ans.push_back(make_pair(u, v));
         dfs(v);
     }
 }
 int main()
 {
     scanf("%d", &T);
     while(T--)
     {
         init();
         scanf("%d%d", &V, &E);
         ; i < E; i++)
         {
             int u, v;
             scanf("%d%d", &u, &v);
             s[u].insert(v);
             s[v].insert(u);
         }
         ; i <= V; i++)
         {
             )
             {
                 s[i].insert(V + );
                 s[V + ].insert(i);
             }
         }
         printf(].size());
         ; i <= V; i++)
             dfs(i);
         ; i < ans.size(); i++)
         {
              && ans[i].second != V + )
                 printf("%d %d\n", ans[i].first, ans[i].second);
         }

     }
     ;
 }

F. st-Spanning Tree

题意:给你一个n个顶点,m个条边的无向联通图,没有自环没有重边,给你两个顶点,和两个值,让你搞出任意一个生成树,使得两个顶点的度数,分别不超过这两个值。

Codeforces Round #375 (Div. 2)的更多相关文章

  1. Codeforces Round #375 (Div. 2) - D

    题目链接:http://codeforces.com/contest/723/problem/D 题意:给定n*m小大的字符矩阵.'*'表示陆地,'.'表示水域.然后湖的定义是:如果水域完全被陆地包围 ...

  2. Codeforces Round #375 (Div. 2) - C

    题目链接:http://codeforces.com/contest/723/problem/C 题意:给定长度为n的一个序列.还有一个m.现在可以改变序列的一些数.使得序列里面数字[1,m]出现次数 ...

  3. Codeforces Round #375 (Div. 2) - B

    题目链接:http://codeforces.com/contest/723/problem/B 题意:给定一个字符串.只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词 ...

  4. Codeforces Round #375 (Div. 2) - A

    题目链接:http://codeforces.com/contest/723/problem/A 题意:在一维坐标下有3个人(坐标点).他们想选一个点使得他们3个到这个点的距离之和最小. 思路:水题. ...

  5. Codeforces Round #375 (Div. 2) F. st-Spanning Tree 生成树

    F. st-Spanning Tree 题目连接: http://codeforces.com/contest/723/problem/F Description You are given an u ...

  6. Codeforces Round #375 (Div. 2) E. One-Way Reform 欧拉路径

    E. One-Way Reform 题目连接: http://codeforces.com/contest/723/problem/E Description There are n cities a ...

  7. Codeforces Round #375 (Div. 2) D. Lakes in Berland 贪心

    D. Lakes in Berland 题目连接: http://codeforces.com/contest/723/problem/D Description The map of Berland ...

  8. Codeforces Round #375 (Div. 2) B. Text Document Analysis 模拟

    B. Text Document Analysis 题目连接: http://codeforces.com/contest/723/problem/B Description Modern text ...

  9. Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题

    A. The New Year: Meeting Friends 题目连接: http://codeforces.com/contest/723/problem/A Description There ...

  10. Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心

    http://codeforces.com/contest/723/problem/C 题目是给出一个序列 a[i]表示第i个歌曲是第a[i]个人演唱,现在选出前m个人,记b[j]表示第j个人演唱歌曲 ...

随机推荐

  1. BZOJ1483: [HNOI2009]梦幻布丁

    传送门 名字起得很高端实际上很简单的算法hhh 启发式合并 简单讲就是一些合并一堆队列的题可以用启发式合并,或者说这是一个思想.每次把小的合并到大的部分,均摊复杂度$O(MlogN)$. //BZOJ ...

  2. 转 PresentViewController切换界面

    视图切换,没有NavigationController的情况下,一般会使用presentViewController来切换视图并携带切换时的动画, 其中切换方法如下: – presentViewCon ...

  3. js分页小结

     今天解决了JS分页的问题1 页码 给每页的内容套一个相同的类名 通过选择器加上.length或者.size() 来获得总页数2当前页的页码可以使用each(function(index,DOMsss ...

  4. Google 地图 API V3 使用入门

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...

  5. Node.js入门笔记(1):基本概念

    Node.js和JavaScript: 核心都是ECMAScrit,比如数据类型,语法结构,内置对象等等. 但是在js中顶层是window 在node中的不存在这个window(console.log ...

  6. Mac OSX定位命令路径的方法

    可以使用which命令来定位一个命令. http://www.cyberciti.biz/faq/how-do-i-find-the-path-to-a-command-file/

  7. WebPack常用功能介绍

    概述 Webpack是一款用户打包前端模块的工具.主要是用来打包在浏览器端使用的javascript的.同时也能转换.捆绑.打包其他的静态资源,包括css.image.font file.templa ...

  8. Android之layout_gravity与gravity解析

    相信layout_gravity和gravity这两个属性一直困扰着很多人,很多初学者都分不清这两个属性有什么区别,以及怎样区分它们.它们中,有一个表示的是一个控件在父布局中的位置,而另一个表示的是一 ...

  9. Linux文件(区域)锁函数 -- open()、fcntl()

    一.什么是文件锁定 对于锁这个字,大家一定不会陌生,因为我们生活中就存在着大量的锁,它们各个方面发挥着它的作用,现在世界中的锁的功能都可归结为一句话,就是阻止某些人做某些事,例如,门锁就是阻止除了屋主 ...

  10. Linux设置Memcached开机启动

    Memcached开机启动方式 方法一: 在 /etc/rc.d/rc.local 文件中追加启动命令 /usr/local/memcached/bin/memcached  -u root -d - ...