ecjtu-summer training #12

A - The Trip, 2007

小包可以放在打包里,求最少的数量。

做法就是求出现相同数字最多的。

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #include <string>
 6 #include <queue>
 7 #include <vector>
 8 #include <set>
 9 #include <map>
10 #define ll long long
11 #define INF 0x3f3f3f3f
12 #define lowbit(x) x&(-x)
13 #define N 10010
14 #define M 110
15 using namespace std;
16 int a[N];
17 int main() {
18     ios::sync_with_stdio(false);
19     int n;
20     bool flag = false;
21     while(cin>>n) {
22         if(n == 0) break;
23         memset(a,0,sizeof(a));
24         for(int i = 1; i <= n; i ++) cin >> a[i];
25         sort(a+1,a+n+1);
26         int k = -1, ans = 1;
27         for(int i = 2; i <= n; i ++) {
28             if(a[i] == a[i-1]) {
29                 ans++;
30                 if(i == n && ans > k) k = ans;
31             }else {
32                 if(ans > k) k = ans;
33                 ans = 1;
34             }
35         }
36         if(flag) printf("\n");
37         else flag = true;
38         printf("%d\n",k);
39         for(int i = 1; i <= k; i ++) {
40             bool flag1 = false;
41             for(int j = i; j <= n; j += k) {
42                 if(!flag1) {
43                     printf("%d",a[j]);
44                     flag1 = true;
45                 }else printf(" %d",a[j]);
46             }
47             printf("\n");
48         }
49     }
50     return 0;
51 }

B - Partitioning by Palindromes

传送

C - Seek the Name, Seek the Fame

The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the innovative little cat works out an easy but fantastic algorithm:

Step1. Connect the father‘s name and the mother‘s name, to a new string S.

Step2. Find a proper prefix-suffix string of S (which is not only the prefix, but also the suffix of S).

Example: Father=‘ala‘, Mother=‘la‘, we have S = ‘ala‘+‘la‘ =
‘alala‘. Potential prefix-suffix strings of S are {‘a‘, ‘ala‘, ‘alala‘}.
Given the string S, could you help the little cat to write a program to
calculate the length of possible prefix-suffix strings of S? (He might
thank you by giving your baby a name:)

Input

The input contains a number of test cases. Each test case
occupies a single line that contains the string S described above.

Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.

Output

For each test case, output a single line with integer numbers in
increasing order, denoting the possible length of the new baby‘s name.

Sample Input

ababcababababcabab
aaaaa

Sample Output

2 4 9 18
1 2 3 4 5

KMP模板题。
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 using namespace std;
 5 char str[400010];
 6 int nex[400010];
 7 int a[400010];
 8 void init(){
 9     int j = nex[0] = -1, i = 0;
10     int len = strlen(str);
11     while(i < len){
12         if(j == -1 || str[i] == str[j]) nex[++i] = ++j;
13         else j = nex[j];
14     }
15 }
16 int main(){
17     while(scanf("%s",str)!=EOF){
18         init();
19         int k = 0,len = strlen(str);
20         int i = len;
21         while(nex[i]){
22             a[k++] = nex[i];
23             i = nex[i];
24         }
25         for(int i = k-1; i >= 0; i --){
26             printf("%d ",a[i]);
27         }
28         printf("%d\n",len);
29     }
30     return 0;
31 }

D - Counting Triangles

传送。

E - Hyper Prefix Sets

英语是硬伤啊,看不懂题目,快结束时才看懂,可惜没时间了。

就是给定n个字符串,求前缀相同的数量乘以长度的最大值。

比如第一组数据。{0000,0001,10101,010},最大值是求前缀000,这时有两个,所以是6.

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #include <string>
 6 #include <queue>
 7 #include <vector>
 8 #include <set>
 9 #include <map>
10 #define ll long long
11 #define INF 0x3f3f3f3f
12 #define lowvit(x) x&(-x)
13 #define N 50010
14 #define M 210
15 using namespace std;
16 char str[M];
17 struct Nod {
18     int num;
19     Nod * next[11];
20     Nod(){
21         for(int i = 0; i < 10; i ++)
22             next[i] = NULL;
23         num = 0;
24     }
25 };
26 int len;
27 void mkTree(Nod *p,char *str) {
28     for(int i = 0; i < len; i ++) {
29         int x = str[i] - ‘0‘;
30         if(p->next[x] == NULL) {
31             p->next[x] = new Nod;
32         }
33         p = p->next[x];
34         p->num++;
35     }
36 }
37 int MAX = -1;
38 void dfs(Nod *p, int x) {
39     for(int i = 0; i < 10; i ++) {
40         if(p->next[i] != NULL) {
41             Nod *p1 = p->next[i];
42             int ans = p1->num;
43             if(MAX < ans*(x+1)) {
44                 MAX = ans*(x+1);
45                 // printf("%d %d \n",ans,(x+1));
46             }
47             dfs(p1,x+1);
48         }
49     }
50     return ;
51 }
52
53 int main() {
54     ios::sync_with_stdio(false);
55     int t, n;
56     cin>>t;
57     while(t--) {
58         Nod *root = new Nod;
59         cin>>n;
60         for(int i = 0; i < n; i ++) {
61             cin>>str;
62             len = strlen(str);
63             mkTree(root,str);
64         }
65         MAX = 0;
66         dfs(root, 0);
67         printf("%d\n",MAX);
68     }
69     return 0;
70 }

F - Triangle Fun

传送

时间: 2024-07-31 20:09:46

ecjtu-summer training #12的相关文章

SDKD 2017 Summer Team Training #12, tm--A(Queries )

题目大意: 给你一个数组,给你如下几种操作: s l r mod 查询区间[l,r]中模m等于mod的数字之和: + p r 将p位置的数加上r后模m: - p r 将p位置的数减去r后模m: 解题思路: 一般进行区间查询,位置操作可以使用线段树或者树状数组解决(暂时只会树状数组):这题的特殊之处就在于要求模m等值: 由于m的值较小(m<10) 因此我们可以开一个二重的树状数组,第二重保存模m后的值:其余操作就是基本的树状~ #include <iostream> #include &l

SDKD 2017 Summer Team Training #12, tm ( Yet Another Median Task )

题目大意:给定一个矩阵,给你多次查询,查询一个小矩阵中的数的中位数: 解题思路:完全没往二分上想,我们可以二分枚举中位数数值,搜索矩阵中数值小于中位数的个数. #include <cstdio> #include <iostream> #include <string.h> #include <string> #include <map> #include <queue> #include <vector> #includ

应用高斯分布来解决异常检测问题(二)

(原创文章,转载请注明出处!) 在文章应用高斯分布来解决异常检测问题(一)中对如何使用高斯分布来解决异常检测问题进行了描述,本篇是使用R编程实现了第一篇中所描述的两个模型:多个一元高斯分布模型和一个多元高斯分布模型. 一. 多个一元高斯分布模型 1 ## parameters: 2 ## x - a vector, which is the data of new samples. 3 ## X - a matrix, which stores samples' data. 4 ## param

vc编程中的20点小笔记

机器学习是一项经验技能,经验越多越好.在项目建立的过程中,实践是掌握机器学习的最佳手段.在实践过程中,通过实际操作加深对分类和回归问题的每一个步骤的理解,达到学习机器学习的目的. 预测模型项目模板不能只通过阅读来掌握机器学习的技能,需要进行大量的练习.本文将介绍一个通用的机器学习的项目模板,创建这个模板总共有六个步骤.通过本文将学到: 端到端地预测(分类与回归)模型的项目结构. 如何将前面学到的内容引入到项目中. 如何通过这个项目模板来得到一个高准确度的模板. 副诼匚盼胁臼匾膊讶赖期放判鼻懒合谖

ECJTU 2018 Summer Training 2

Thanks a lot for helping Harry Potter in finding the Sorcerer's Stone of Immortality in October. Did we not tell you that it was just an online game ? uhhh! now here is the real onsite task for Harry. You are given a magrid S ( a magic grid ) having

2014 Super Training #1 F Passage 概率DP

原题: HDU 3366   http://acm.hdu.edu.cn/showproblem.php?pid=3366 本来用贪心去做,怎么都WA,后来看网上原来是一个DP题. 首先按P/Q来做排序,即P越大,Q越小就越好,这样可以确保先选最优的路走. dp[i][j]表示已经到了第i条路(说明前i-1条都没成功的情况),还剩j块钱时能够走出去的概率. 则方程: dp[i][j] = way[i].P + way[i].Q*(dp[i+1][j-1]) + way[i].D*(dp[i+1]

2017 UESTC Training for Dynamic Programming

2017 UESTC Training for Dynamic Programming A    思维, 或 dp, 很有意思 方法1: 构造法:蛇形安排赛程表算法复杂度:O(N^2)将1-N排成两竖列,每一轮同一行的为对手保持1的位置不变,其他位置按顺(逆)时方向依次旋转1    6          1    2          1    3          1    4          1    5      2    5          3    6          4   

湖南省第十三届大学生计算机程序设计竞赛 Football Training Camp 贪心

2007: Football Training Camp[原创-转载请说明] Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 228     Solved: 30 Description 在一次足球联合训练中一共有n支队伍相互进行了若干场比赛. 对于每场比赛,赢了的队伍得3分,输了的队伍不得分,如果为平局则两支队伍各得1分. Input 输入包含不超过1000组数据. 每组数据的第

docker深入2-熟悉v1.12

2016/7/30 前言:2016/7/28,v1.12这个版本release,最重要的特色是swarm mode,快去琢磨一下吧. 一.基础环境 1.系统版本 [[email protected] ~]# cat /etc/redhat-release  CentOS Linux release 7.1.1503 (Core)  [[email protected] ~]# uname -a                 Linux n36 3.10.0-229.el7.x86_64 #1