题目链接: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)的更多相关文章

  1. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes

                                                        D. Prefixes and Suffixes You have a string s = s ...

  2. Codeforces Round #246 (Div. 2) C. Prime Swaps(贪心,数论)

    题目链接:http://codeforces.com/contest/432/problem/C 首先由题意分析出:这些数是从1到n且各不相同,所以最后结果肯定是第i位的数就是i. 采用这样一种贪心策 ...

  3. Codeforces Round #246 (Div. 2) B. Football Kit

    题目的意思是求出每个队穿主场衣服和客场衣服的次数 每个队作为主场的次数是n-1,作为客场的次数是n-1 当每个队打主场的时候肯定穿的主场衣服 当每个队打客场时,如果客场与主场的衣服不同,则穿客场衣服 ...

  4. Codeforces Round #246 (Div. 2) A. Choosing Teams

    给定n k以及n个人已参加的比赛数,让你判断最少还能参加k次比赛的队伍数,每对3人,每个人最多参加5次比赛 #include <iostream> using namespace std; ...

  5. Codeforces Round #246 (Div. 2)——D题

    KMP算法,没写出来,完全不理解NEXT数组.现在理解了很多 答案都在程序中 ,不过这个思想真的很神奇, 还有毛语不好,一直没看懂题目,现在懂了, 大概是:S中前缀等于后缀,求其长度,和其在S中出现了 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #246 (Div. 2) D E

    这题说的是给了一个字符串当前缀和后缀相同的时候就计算此时的 整个串种拥有这样的子串友多少个,没想到用KMP解 用0开头的那种类型的 KMP 今天刚好也学了一下,因为KMP的作用是找出最长前缀 KMP ...

  9. 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 ...

随机推荐

  1. PHPExcel 导出

    <?php include '../init.inc.php'; include "../db.inc.php"; /* @func 引入类 */ include ROOT. ...

  2. BZOJ 2733: [HNOI2012]永无乡(treap + 启发式合并 + 并查集)

    不难...treap + 启发式合并 + 并查集 搞搞就行了 --------------------------------------------------------------------- ...

  3. 建造者模式->代码示例

    <?php interface Builder{ public function head(); public function body(); public function foot(); ...

  4. A Byte of Python 笔记(7)数据结构:列表、元组、字典,序列

    第9章 数据结构 数据结构,即可以处理一些数据的结构.或者说,它们是用来存储一组相关数据的. python 有三种内建的数据结构--列表.元组和字典. list = ['item1', 'item2' ...

  5. w3wp.exe CPU过百问题

    w3wp.exe CPU过百问题 最近发布在windows  server2012  IIS8.0上的一个WebAPI项目,才几十个人在线,CPU就会出现过百情况,并且CPU一旦过百应用程序池就自动暂 ...

  6. HDU 3231 Box Relations

    题目大意: 给定一些正方体的关系,要求一组符合这些关系的正方体坐标,如果不存在符合条件的正方体坐标,IMPOSSIBLE.(Special Judge) 实力还是太弱了,完全不会…… #include ...

  7. [Python]Unicode转ascii码的一个好方法

    写这篇文章的是一位外国人,他遇到了什么问题呢?比如有一个 Unicode 字符串他需要转为 ascii码: >>> title = u"Klüft skräms inför ...

  8. 《UNIX环境高级编程》笔记--UNIX标准化及实现

    1.UNIX标准化 1.1.ISO C 1989 年后期,C程序设计语言的ANSI(American National Standards Institute) 标准X3. 15 9-1989得到批准 ...

  9. javadoc入门

    斌斌 (给我写信) 原创博文(http://blog.csdn.net/binbinxyz),转载请注明出处! java凝视 java里面有两种类型的凝视.一种是以"/*"起头,以 ...

  10. Android 中文API (65) —— BluetoothClass[蓝牙]

    前言 本章内容是android.bluetooth.BluetoothClass,为Android蓝牙部分的章节翻译.用于描述远端设备的类型,特点等信息,通过getBluetoothClass()方法 ...