Codeforces Round #246 (Div. 2)
题目链接:Codeforces Round #246 (Div. 2)
A:直接找满足的人数,然后整除3就是答案
B:开一个vis数组记录每一个衣服的主场和客场出现次数。然后输出的时候主场数量加上反复的,客场数量减掉反复的
C:原来是YY乱搞的。原来是哥德巴赫猜想,一个合数能够表示为3个质数相加,然后就先打个素数表,然后从最小的数字一个个模拟往前放就可以。放的时候走的步数直接拆成都是质数就可以
D:KMP算法,利用next数组性质求前缀和后缀匹配,然后在利用累加求和求出每一个串相应的出现次数
代码:
A:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int n, k, num, i; int main() {
scanf("%d%d", &n, &k);
int ans = 0;
for (i = 0; i < n; i++) {
scanf("%d", &num);
if (5 - num >= k) ans++;
}
printf("%d\n", ans / 3);
return 0;
}
B:
#include <stdio.h>
#include <string.h> const int N = 100005;
int vis[N][2];
int n, x[N], y[N], i; int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &x[i], &y[i]);
vis[x[i]][0]++;
vis[y[i]][1]++;
}
for (i = 0; i < n; i++) {
printf("%d %d\n", (n - 1) + vis[y[i]][0], (n - 1) - vis[y[i]][0]);
}
return 0;
}
C:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 100005; int pri[N], ans[5 * N][2], ansn = 0; void init() {
int vis[N];
memset(vis, 0, sizeof(vis));
for (int i = 2; i < N; i++) {
if (vis[i]) continue;
pri[i] = 1;
for (int j = i; j < N; j += i)
vis[j] = 1;
}
} int n, num[N], v[N], i, snum[N]; void swap(int &a, int &b) {
a ^= b;
b ^= a;
a ^= b;
} int main() {
init();
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &num[i]);
snum[i] = num[i];
v[num[i]] = i;
}
sort(snum, snum + n);
i = 0;
while (i < n) {
while (v[snum[i]] != i) {
for (int j = i; ;j++) {
if (pri[v[snum[i]] - j + 1]) {
ans[ansn][0] = j + 1;
ans[ansn][1] = v[snum[i]] + 1;
ansn++;
int t = v[snum[i]];
v[snum[i]] = j;
v[num[j]] = t;
swap(num[j], num[t]);
break;
}
}
}
i++;
}
printf("%d\n", ansn);
for (i = 0; i < ansn; i++)
printf("%d %d\n", ans[i][0], ans[i][1]);
return 0;
}
D:
#include <stdio.h>
#include <string.h>
#define INF 0x3f3f3f3f
const int N = 100005; char s[N];
int next[N], n, ans[N], ansn = 0; void get_next(char *seq, int m) {
next[1] = 0;
int j = next[1];
for (int i = 2; i <= m; i++) {
while (j && seq[i] != seq[j + 1]) j = next[j];
if (seq[i] == seq[j + 1]) j++;
next[i] = j;
}
} int vis[N]; int main() {
int i = 0;
scanf("%s", s + 1);
n = strlen(s + 1);
get_next(s, n);
int t = next[n];
while (t) {
ans[ansn++] = t;
t = next[t];
}
for (i = n; i > 0; i--)
vis[next[i]]++;
for (i = n; i > 0; i--)
vis[next[i]] += vis[i];
printf("%d\n", ansn + 1);
for (i = ansn - 1; i >= 0; i--)
printf("%d %d\n", ans[i], vis[ans[i]] + 1);
printf("%d %d\n", n, vis[n] + 1);
return 0;
}
Codeforces Round #246 (Div. 2)的更多相关文章
- Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes
D. Prefixes and Suffixes You have a string s = s ...
- Codeforces Round #246 (Div. 2) C. Prime Swaps(贪心,数论)
题目链接:http://codeforces.com/contest/432/problem/C 首先由题意分析出:这些数是从1到n且各不相同,所以最后结果肯定是第i位的数就是i. 采用这样一种贪心策 ...
- Codeforces Round #246 (Div. 2) B. Football Kit
题目的意思是求出每个队穿主场衣服和客场衣服的次数 每个队作为主场的次数是n-1,作为客场的次数是n-1 当每个队打主场的时候肯定穿的主场衣服 当每个队打客场时,如果客场与主场的衣服不同,则穿客场衣服 ...
- Codeforces Round #246 (Div. 2) A. Choosing Teams
给定n k以及n个人已参加的比赛数,让你判断最少还能参加k次比赛的队伍数,每对3人,每个人最多参加5次比赛 #include <iostream> using namespace std; ...
- Codeforces Round #246 (Div. 2)——D题
KMP算法,没写出来,完全不理解NEXT数组.现在理解了很多 答案都在程序中 ,不过这个思想真的很神奇, 还有毛语不好,一直没看懂题目,现在懂了, 大概是:S中前缀等于后缀,求其长度,和其在S中出现了 ...
- Codeforces Round #246 (Div. 2) —B. Football Kit
B. Football Kit time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes(后缀数组orKMP)
D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #246 (Div. 2) D E
这题说的是给了一个字符串当前缀和后缀相同的时候就计算此时的 整个串种拥有这样的子串友多少个,没想到用KMP解 用0开头的那种类型的 KMP 今天刚好也学了一下,因为KMP的作用是找出最长前缀 KMP ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- Winform获取当前程序名称或路径
以下几种方法获取当前程序名称或路径: // 获取程序的基目录. System.AppDomain.CurrentDomain.BaseDirectory // 获取模块的完整路径. // 获 ...
- org.apache.tomcat.util.bcel.classfile.ClassFormatException: null is not a Java .class file
org.apache.tomcat.util.bcel.classfile.ClassFormatException: null is not a Java .class file 在$TOMCA ...
- 常用上网增强类Chrome扩展(转)
Chrome是个非常好用的浏览器,拥有丰富的扩展资源库,能够满足网民各种各样的需求,对于网民来说,通过Chrome扩展来增强上网体验是一个基本需求,但是安装过多的扩展有容易耗费大量系统资源,今天月光博 ...
- malloc/free和new/delete的区别汇总
一.基本概念 malloc/free 1.函数原型及说明: void* malloc(long NumBytes):该函数分配了NumBytes个字节,并返回了指向这块内存的指针.如果分配失败,则返回 ...
- 5.6.3.4 trim()方法
ECMAScript 5 为所有字符串定义了trim()方法.这个方法会创建一个字符串的副本,删除前置以及后缀的所有空格,然后返回结果.例如: var stringValue = " hel ...
- html5 存储篇(一)
localStorage 和 sessionStorage localStorage 与 sessionStorage的相同点: (1).都是用于客户端存储的技术,相对于传统 ...
- 11-C语言指针
目录: 一.指针 二.指针与数组 回到顶部 一.指针 1 内存被分为字节,每个字节有唯一地址,指针保存的是内存中的地址. 2 保存指针的变量,就叫指针变量,(保存地址) 3 声明一个指针变量 int ...
- what does Html.HiddenFor () for ?
When I want to pass some value that won't be seen by users, I find it useful to use this. It can hel ...
- web 性能优化指南阅读笔记
1.关于拥塞预防算法 PRR-比例降速,RFC6937 规定的一个新算法,其目标是改进丢包后的恢复速度,谷歌测量结果:该算法改进丢包造成的平均连接延迟减少了3%-10%.PRR是linux 3.2+内 ...
- golang ODBC 访问access数据库(问题解决之心理路程)
最近项目需要,需要操作access,以前是用VC++ OLE访问,网络用ACE库,感觉很庞大...决定用go试试 网上用的最多的就是这个https://github.com/weigj/go-odbc ...