题目链接:http://hihocoder.com/contest/hihointerview12

期末完事了,终于有时间成套刷题了。这套题比较简单,难度上感觉和上一套差不多。除了最后一个题是看了讨论版说数据水才敢写的。

A Word Construction

解法:正解应该是dfs+剪枝,我的思路是贪心,竟然过了。先把字符串按字典序排序,然后枚举每一个串作为起始,记下串内有什么字符,再从头到尾枚举所有字符串,看看每一个是否符合条件。就那么100个字符串,数据弱得很。

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<LL, LL> pll;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
string s[maxn];
int n;
int ascii[]; int main() {
// FRead();
while(~Rint(n)) {
Rep(i, n) cin >> s[i];
sort(s, s+n);
int ret = ;
Rep(k, n) {
Cls(ascii);
Rep(j, s[k].length()) ascii[s[k][j]] = ;
int cur = ;
Rep(i, n) {
bool flag = ;
Rep(j, s[i].length()) {
if(ascii[s[i][j]] == ) {
flag = ;
break;
}
}
if(flag == ) {
Rep(j, s[i].length()) ascii[s[i][j]] = ;
cur++;
}
}
ret = max(ret, cur);
}
printf("%d\n", ret);
}
RT ;
}

A

B Email Merge

解法:STL+并查集,这题很好想,但是写起来比较麻烦。对于字符串数组,想要做并查集操作的话,需要map<string, int>这样从字符串到整型的映射支持。读入数据按照邮箱为根节点,儿子是用户名,构建一个森林。这个时候同时更新并查集,也就是合并同一个树根下的所有用户名字符串。接着遍历所有用户名,扔到对应的belong中。我开的belong是堆,因为输出要求按照出现的顺序,所以堆序就是输入的顺序,也就是之前赋值的id号。

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<LL, LL> pll;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
typedef struct Node {
string d;
int idx;
Node() { idx = -; }
Node(string dd, int ii) : d(dd), idx(ii) {}
friend bool operator<(Node a, Node b) { return a.idx > b.idx; }
}Node; string mail, user;
bool vis[maxn];
map<string, int> id;
map<string, set<string> > wt;
priority_queue<Node> belong[]; int n, m, cnt;
int pre[maxn]; int find(int x) {
return x == pre[x] ? x : pre[x] = find(pre[x]);
} void unite(int x, int y) {
x = find(x); y = find(y);
if(x < y) pre[y] = x;
else pre[x] = y;
} int main() {
// FRead();
cnt = ;id.cl(); wt.cl(); Cls(vis);
Rint(n);
Rep(i, n*) {
pre[i] = i;
while(!belong[i].empty()) belong[i].pop();
}
Rep(i, n) {
cin >> user;
cin >> m;
id[user] = cnt++;
Rep(j, m) {
cin >> mail;
if(id.find(mail) == id.end()) id[mail] = cnt++;
wt[mail].insert(user);
unite(id[user], id[mail]);
}
}
map<string, set<string> >::iterator it;
set<string>::iterator each;
for(it = wt.begin(); it != wt.end(); it++) {
for(each = it->second.begin(); each != it->second.end(); each++) {
if(!vis[id[*each]]) {
vis[id[*each]] = ;
belong[find(id[*each])].push(Node(*each, id[*each]));
}
}
}
Rep(i, cnt) {
if(!belong[i].empty()) {
while(!belong[i].empty()) {
cout << belong[i].top().d << " ";
belong[i].pop();
}
cout << endl;
}
}
RT ;
}

B

C Matrix Sum

解法:这题毒瘤题…数据里有负数,不同语言对负数取模运算的结果不一样,C++和Java是一个负数对一个正数取模是一个负数,而Python是正数。这题的正解应当是二维线段树or树状数组(树套树),分别维护自己列的值。而我直接维护前缀和了。写了各种语言的解法,改来改去最后改了java。

 import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner; import javax.swing.text.GapContent; public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n, m;
int[][] dp = new int[1010][1010];
String cmd = new String();
for(int i = 0; i < 1010; i++) {
for(int j = 0; j < 1010; j++) {
dp[i][j] = 0;
}
}
n = in.nextInt(); m = in.nextInt();
int x1, x2, y1, y2, num;
while(m-- > 0) {
cmd = in.next();
if(cmd.charAt(0) == 'A') {
x1 = in.nextInt();
y1 = in.nextInt();
num = in.nextInt();
for(int i = y1; i < n; i++) {
dp[x1][i] = (dp[x1][i] + num) % 1000000007;
}
}
else {
x1 = in.nextInt();
x2 = in.nextInt();
y1 = in.nextInt();
y2 = in.nextInt();
int ret = 0;
for(int i = x1; i <= y1; i++) {
if(x2 == 0) ret = (ret + dp[i][y2]) % 1000000007;
else ret = (ret + dp[i][y2] - dp[i][x2-1]) % 1000000007;
}
System.out.println((ret + 1000000007) % 1000000007);
}
}
}
}

C

[HIHO]hihoCoder太阁最新面经算法竞赛7的更多相关文章

  1. Hihocoder 太阁最新面经算法竞赛18

    Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...

  2. hihoCoder太阁最新面经算法竞赛15

    hihoCoder太阁最新面经算法竞赛15 Link: http://hihocoder.com/contest/hihointerview24 题目1 : Boarding Passes 时间限制: ...

  3. hihocoder Round #c1(hihoCoder太阁最新面经算法竞赛1 )

    Test链接:https://cn.vjudge.net/contest/231849 选自hihoCoder太阁最新面经算法竞赛1 更多Test:传送门 A:区间求差 给一组区间集合A和区间集合B, ...

  4. hihoCoder太阁最新面经算法竞赛19

    比赛链接:http://hihocoder.com/contest/hihointerview28/problems A. 固定一个方向,两两相邻的点顺时针或逆时针构造三个向量,判断这个点在这个向量的 ...

  5. hihoCoder太阁最新面经算法竞赛18

    比赛链接:http://hihocoder.com/contest/hihointerview27/problems A.Big Plus 模拟水 #include <bits/stdc++.h ...

  6. hihoCoder太阁最新面经算法竞赛17

    比赛链接:http://hihocoder.com/contest/hihointerview26 A.排序后枚举两个点,确定一个矩形后二分剩下两个点. #include <bits/stdc+ ...

  7. zz 圣诞丨太阁所有的免费算法视频资料整理

    首发于 太阁实验室 关注专栏   写文章     圣诞丨太阁所有的免费算法视频资料整理 Ray Cao· 12 小时前 感谢大家一年以来对太阁实验室的支持,我们特地整理了在过去一年中我们所有的原创算法 ...

  8. [刷题]算法竞赛入门经典 3-12/UVa11809

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa11809:Floating-Point Numbers 代码: //UVa11 ...

  9. [刷题]算法竞赛入门经典 3-1/UVa1585 3-2/UVa1586 3-3/UVa1225

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO(我也是在网上找到的pdf,但不记得是从哪里搜刮到的了,就重新上传了一遍) PS:第一次写博客分享我的代码,不知道我对c ...

随机推荐

  1. ios 百度地图

    百度地图  中的注意事项 1. 百度地图中 使用了c++   设置buidSeting compoileSource 为 Object-C++  强制使用oc++编译器 2. 设置  BuidSeti ...

  2. iOS7 状态栏 修改为白色字体的步骤

    1在Info.plist中设置UIViewControllerBasedStatusBarAppearance 为NO2 在需要改变状态栏颜色的ViewController中在ViewDidLoad方 ...

  3. UITbaleView上按钮的单选

    设置Id属性,标记是哪个cell @property (nonatomic,assign)NSInteger Id; 设置一个普通状态和选中状态图片不同的按钮 _choose = [[UIButton ...

  4. 使用Visio进行UML建模

    http://www.qdgw.edu.cn/zhuantiweb/jpkc/2009/rjkf/xmwd/Visio_UmlModel.htm#_Toc80417837 内容提纲: 1.VISIO中 ...

  5. ASP 中调用函数关于Call使用注意的问题

    Function TestFun(Tstr) TStr = "Fun2" End Function Sub TestSub(TStr) Tstr = "Sub2" ...

  6. 初学Ajax(二)

    $.get()和$.post() .load()方法是局部方法,因为它需要一个包含元素的jQuery对象作为前缀.而$.get()和$.post()是全局方法,无须指定某个元素.对于用途而言,.loa ...

  7. C# winform post请求数据

    刚到公司混的时候,老板要求实现一个从C#的windows应用程序传参数到一个网页,然后这个网页不显示出来,但能把数据返回给应用程序的功能,问了好多人,找了好多资料,都搞不定,后来还是在老板的帮助下搞定 ...

  8. hdu2024C语言合法标识符

    #include<iostream> #include<stdio.h> #include<math.h> #include<stdlib.h> #in ...

  9. centOS学习part2:安装JDK及tomcat

    0 上一篇(http://www.cnblogs.com/souvenir/p/3875424.html)给大家介绍了centOS操作系统的安装,接下来我们来介绍centOS常用软件的安装以及配置,希 ...

  10. java.lang.ClassCastException: sun.jdbc.odbc.JdbcOdbcStatement cannot be cast to java.beans.Statement

    当导入的包为:import java.sql.Statement;时,无任何错误 当导入的包为:import java.beans.Statement;时,出错