题目链接  Problems

Problem A

快速幂累加即可。

#include <cstdio>
#include <cstring>
#include <iostream> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; LL ans = 0;
LL n, d;
int T; const LL mod = 1e9 + 7; inline LL Pow(LL a, LL b, LL Mod){
LL ret(1);
for (; b; b >>= 1, (a *= a) %= Mod) if (b & 1) (ret *= a) %= Mod;
return ret;
} int main(){ scanf("%d", &T);
while (T--){
cin >> n >> d;
ans = 0;
rep(i, 1, n){
ans += Pow(i, d, mod);
ans %= mod;
} printf("%lld\n", ans);
} return 0;
}

Problem B

对于每个帮派,并查集维护就可以了。

求第$k$大的时候树状数组上二分就好了。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const int N = 1e5 + 10; int T;
int sz[N], c[N], father[N];
int n, m;
int num; void update(int x, int val){
for (; x <= n; x += x & -x) c[x] += val;
} int query(int x){
int ret = 0;
for (; x; x -= x & -x) ret += c[x];
return ret;
} int getfather(int x){
return father[x] == x ? x : father[x] = getfather(father[x]);
} int main(){ scanf("%d", &T);
while (T--){
scanf("%d%d", &n, &m);
memset(c, 0, sizeof c);
memset(father, 0, sizeof father);
rep(i, 1, n) father[i] = i; rep(i, 1, n) update(1, 1);
num = n;
rep(i, 1, n) sz[i] = 1;
while (m--){
int op;
scanf("%d", &op);
if (op == 1){
int x, y;
scanf("%d%d", &x, &y);
int fx = getfather(x), fy = getfather(y);
if (fx == fy) continue; father[fy] = fx; int f1 = sz[fx], f2 = sz[fy], f3 = sz[fx] + sz[fy];
sz[fx] += sz[fy];
sz[fy] = 0;
--num; update(f1, -1);
update(f2, -1);
update(f3, 1);
} else{
int x;
scanf("%d", &x);
if (num < x){
puts("-1");
continue;
}
int l = 1, r = n; while (l + 1 < r){
int mid = (l + r) >> 1;
if (num - query(mid - 1) >= x) l = mid;
else r = mid - 1;
} if (num - query(r - 1) >= x) printf("%d\n", r);
else printf("%d\n", l);
}
}
} return 0;
}

Problem C

递推。$f_{n} = 2f_{n-1} + f_{n-3}$

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const int A = 5; const LL mod = 1e9 + 7; struct matrix{ LL a[A][A];} init, unit, aa;
int n;
LL m;
int T; matrix Mul(matrix a, matrix b){
matrix c;
rep(i, 1, n) rep(j, 1, n){
c.a[i][j] = 0;
rep(k, 1, n) (c.a[i][j] += (a.a[i][k] * b.a[k][j] % mod)) %= mod;
}
return c;
} matrix Pow(matrix a, LL k){
matrix ret(unit); for (; k; k >>= 1ll, a = Mul(a, a)) if (k & 1) ret = Mul(ret, a); return ret;
} int main(){ n = 3; matrix dd;
memset(dd.a, 0, sizeof dd.a); memset(unit.a, 0, sizeof unit.a);
rep(i, 1, n) unit.a[i][i] = 1ll; dd.a[1][1] = 2; dd.a[1][2] = 0; dd.a[1][3] = 1;
dd.a[2][1] = 1;
dd.a[3][2] = 1; scanf("%d", &T);
while (T--){
scanf("%lld", &m); LL fuck = m - 3;
if (m <= 3){
if (m == 1ll) puts("1");
if (m == 2ll) puts("2");
if (m == 3ll) puts("5");
continue;
} matrix cc = Pow(dd, fuck); LL ans = cc.a[1][1] * 5ll + cc.a[1][2] * 2ll + cc.a[1][3] * 1ll;
ans %= mod; printf("%lld\n", ans);
} return 0;
}

Problem D

最坏的情况即为斐波那契数列中的某几项。

那么当询问元素个数超过一定的时候(大概$87$)直接输出Yes就好了。

否则就暴力特判。

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; LL a[100010];
LL c[100010];
int n, q;
int cnt = 0; int main(){ scanf("%d", &n);
rep(i, 1, n) scanf("%lld", a + i); scanf("%d", &q);
while (q--){
int l, r;
scanf("%d%d", &l, &r);
if (r - l + 1 >= 100){
puts("Yes");
continue;
}
cnt = 0;
rep(i, l, r) c[++cnt] = a[i]; sort(c + 1, c + cnt + 1); int fg = 0;
rep(i, 1, cnt - 2) if (c[i] + c[i + 1] > c[i + 2]){
fg = 1;
break;
} puts(fg ? "Yes" : "No");
} return 0;
}

Problem E

分解质因数之后令$a_{i}$为每个质因数的指数。

答案为

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; LL n;
int T;
LL bs;
LL cc;
LL ans; int main(){ while (~scanf("%d", &T)){
while (T--){
scanf("%lld", &n);
LL bs = sqrt(n); ans = 1; for (LL i = 2; i <= sqrt(n); ++i){
LL cc = 0;
while (n % i == 0) ++cc, n /= i;
ans *= (2 * cc + 1ll);
} if (n > 1) ans *= 3;
++ans;
ans /= 2;
printf("%lld\n", ans);
}
} return 0;
}

Problem F

答案为$2^{n-3} * n^{2} * (n+3)$

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const LL mod = 1e9 + 7; int T;
LL n, ans; inline LL Pow(LL a, LL b, LL Mod){
LL ret(1);
for (; b; b >>= 1, (a *= a) %= Mod) if (b & 1) (ret *= a) %= Mod;
return ret;
} int main(){ scanf("%d", &T);
while (T--){
scanf("%lld", &n);
if (n == 1ll){
puts("1");
continue;
} if (n == 2ll){
puts("10");
continue;
} if (n == 3ll){
puts("54");
continue;
} LL ans = Pow(2, n - 3, mod);
ans *= n;
ans %= mod;
ans *= n;
ans %= mod;
ans *= (n + 3ll);
ans %= mod; printf("%lld\n", ans);
} return 0;
}

Problem G

从小到大枚举答案,每次做一遍极大极小搜索,若符合题意就直接输出。

#include <cstdio>
#include <cstring>
#include <iostream> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const int N = 2e3 + 10; LL a[N];
LL f[2][N];
LL s[N];
LL xxx;
int n;
int m;
int ans; LL dp(int x, int pos){
if (~f[x][pos]) return f[x][pos]; if (pos == m){
if (x) return f[x][pos] = a[pos];
else return f[x][pos] = 0;
} LL ret = 0;
if (x){
ret = a[pos] + dp(x ^ 1, pos + 1);
ret = max(ret, dp(x, pos + 1));
} else{
ret = dp(x ^ 1, pos + 1);
ret = min(ret, a[pos] + dp(x, pos + 1));
} return f[x][pos] = ret;
} int main(){ while (~scanf("%d", &n) && n != -1){
rep(i, 1, n) scanf("%lld", a + i);
scanf("%lld", &xxx);
s[0] = 0;
rep(i, 1, n) s[i] = s[i - 1] + a[i];
ans = -1;
for (m = 1; m <= n; ++m){
memset(f, -1, sizeof f);
LL gg = dp(1, 1);
if (gg >= xxx){
ans = m;
break;
}
} printf("%d\n", ans);
} return 0;
}

Problem H

贪心。求出每个块的大小,然后枚举每个块。记块的个数为$cnt$

两边的块如果有不小于$2$的,那么答案用$cnt + 1$更新。

中间的块大小如果有不小于$3$的,那么答案用$cnt + 2$更新。

UPD:哦草我好像没考虑0011然后翻转中间的0和1的情况,这也是一个case

代码就不改乐

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const int N = 1e5 + 10; int a[N];
int c[N];
int n, cnt, xx, now;
int ans; int main(){ while (~scanf("%d", &n)){
rep(i, 1, n) scanf("%1d", a + i); xx = -1;
cnt = -1; now = 0;
rep(i, 1, n){
if (a[i] != xx){
c[++cnt] = now;
now = 1;
} else ++now; xx = a[i];
} c[++cnt] = now;
ans = cnt;
if (c[1] == 2 || c[cnt] == 2) ans = max(ans, cnt + 1);
rep(i, 1, cnt) if (c[i] >= 3) ans = max(ans, cnt + 2);
printf("%d\n", ans);
} return 0;
}

Problem I

模拟题。

#include <cstdio>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <cstring> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; char s[11010];
int T;
set <string> mp;
int l;
int n;
set <string> :: iterator it; int judge(char ch){
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch == '-') || (ch == '_')) return 1;
return 0;
} int main(){ scanf("%d", &T);
while (T--){
mp.clear();
scanf("%d", &n);
getchar(); rep(op, 1, n){
gets(s);
l = strlen(s); string s1 = "";
int i;
for (i = 0; i < l; ++i){
if (s[i] == '@'){
if (i && judge(s[i - 1])) continue;
s1 = "";
for (; i + 1 < l && judge(s[i + 1]); ){
s1 += s[i + 1];
++i;
} if (s1 != "") mp.insert(s1);
}
} } printf("%d\n", (int)mp.size());
for (it = mp.begin(); it != mp.end(); ++it) cout << *it << endl;
} return 0;
}

Problem J

签到。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; int a[100010], b[100010];
int n ;
int T; int main(){ scanf("%d", &T);
while (T--){
scanf("%d", &n);
rep(i, 1, n) scanf("%d", a + i);
rep(i, 1, n) scanf("%d", b + i); int ff = 1, fg = 1; rep(i, 1, n) if (a[i] > b[i]) ff = 0;
rep(i, 1, n) if (a[i] > b[n - i + 1]) fg = 0; if (ff && fg) puts("both");
else if (ff && !fg) puts("front");
else if (!ff && fg) puts("back");
else puts("none");
} return 0;
}

"科林明伦杯"哈尔滨理工大学第八届程序设计竞赛 题解的更多相关文章

  1. 【数论&想法题】小C的问题 @"科林明伦杯"哈尔滨理工大学第八届程序设计竞赛

    Time Limit: 1000 MS Memory Limit: 256000 K Description 小C是一个可爱的女孩,她特别喜欢世界上最稳定的图形:三角形.有一天她得到了n根木棍,她把这 ...

  2. ACM-南京理工大学第八届程序设计竞赛-网络赛(2016.04.17)

    A.偷吃糖果Time Limit: 1000Ms Memory Limit: 65536KB Description小鱼喜欢吃糖果.他有两盒糖果,两盒糖果分别仅由小写字母组成的字符串s和字符串t构成. ...

  3. A. Srdce and Triangle--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    如下图这是“今日头条杯”首届湖北省大学程序设计竞赛的第一题,作为赛后补题 题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 Let  be a regualr tr ...

  4. 《ACM国际大学生程序设计竞赛题解Ⅰ》——基础编程题

    这个专栏开始介绍一些<ACM国际大学生程序设计竞赛题解>上的竞赛题目,读者可以配合zju/poj/uva的在线测评系统提交代码(今天zoj貌似崩了). 其实看书名也能看出来这本书的思路,就 ...

  5. 电信学院第一届新生程序设计竞赛题解及std

    首先非常感谢各位同学的参加,还有出题验题同学的辛勤付出 昨天想偷懒就是不想再把我C++11的style改没了,大家看不懂的可以百度一下哦,懒得再写gcc了,毕竟代码是通的 //代表的是行注释,所以那个 ...

  6. 哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(高年级) Solution

    A: Solved. 分别处理出每个%7后余数的数字个数,再组合一下 #include <bits/stdc++.h> using namespace std; #define ll lo ...

  7. 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题

    B - 大还是小? Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Description 输入两个实数,判断第一个数大 ...

  8. “东信杯”广西大学第一届程序设计竞赛(同步赛)H

    链接:https://ac.nowcoder.com/acm/contest/283/H来源:牛客网 题目描述 由于临近广西大学建校90周年校庆,西大开始了喜闻乐见的校园修缮工程! 然后问题出现了,西 ...

  9. "字节跳动杯"2018中国大学生程序设计竞赛-女生专场 Solution

    A - 口算训练 题意:询问 $[L, R]$区间内 的所有数的乘积是否是D的倍数 思路:考虑分解质因数 显然,一个数$x > \sqrt{x} 的质因子只有一个$ 那么我们考虑将小于$\sqr ...

随机推荐

  1. [转]赵桐正thinkphp教程笔记

    原文:赵桐正thinkphp教程笔记 ,有修改 常用配置 常用配置config.php: <?php return array( //'配置项'=>'配置值' 'URL_PATHINFO_ ...

  2. 玩转Openstack之Nova中的协同并发(一)

    玩转Openstack之Nova中的协同并发(一) 前不久参加了个Opnstack的Meetup,其中有一个来自EasyStack的大大就Nova中的协同并发做了一番讲解,有所感触,本想当天就总结一下 ...

  3. NBA投篮

    D 辅助插件:原生 游戏制作难度系数:初级 游戏教程网址:http://www.raywenderlich.com/20333/beginning-unity-3d-for-ios-part-1 1. ...

  4. 孤荷凌寒自学python第四十三天python 的线程同步之Queue对象

     孤荷凌寒自学python第四十三天python的线程同步之Queue对象 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) Queue对象是直接操作队列池的对象,队列中可以存放多种对象,当然也 ...

  5. RelativeLayout布局属性

    Android RelativeLayout属性 // 相对于给定ID控件 android:layout_above 将该控件的底部置于给定ID的控件之上; android:layout_below ...

  6. C++ Primer 第2章 变量和基本类型

    C++ Primer 第2章 变量和基本类型 C Primer 第2章 变量和基本类型 1 基本内置类型 算数类型 类型转换 字面值常量 2 变量 变量定义 3 复合类型 引用d左引用 指针d 4 c ...

  7. linux socket c/s上传文件

    这是上传文件的一个示例,可以参照自行修改成下载或者其它功能. 在上传时,需要先将文件名传到服务器端,这是采用一个结构体,包含文件名及文件名长度(可以用于校验),防止文件名乱码. client #inc ...

  8. ZOJ 3724 Delivery 树状数组好题

    虽然看起来是求最短路,但因为条件的限制,可以转化为区间求最小值. 对于一条small path [a, b],假设它的长度是len,它对区间[a, b]的影响就是:len-( sum[b]-sum[a ...

  9. form表单文件上传 servlet文件接收

    需要导入jar包 commons-fileupload-1.3.2.jar commons-io-2.5.jar Upload.Jsp代码 <%@ page language="jav ...

  10. Linux下磁盘管理

    设置密码mkpasswdmkpasswd -s 0mkpasswd -s 0 -1 15 规定密码的长度 1. 查看磁盘或者目录的容量df 查看磁盘各分区使用情况 不加参数以k为单位 df -i in ...