【前言】
周六第一天跑到实验室复习。
复习到一半看到有个contest。看了一题,觉得可以做,然后就YY了。
然后一发就不可收拾了……
确实是好久没做ACM了,最近都忙着大作业。
【题解】
首先看到第三题。由于那些题目是hdu没有的,所以只能把题目也copy过来了。
由于每个数都很小,所以开个数组存一下就可以了。
于是就把水题敲出来了。看来我水题帝的称号还是名副其实的啊。
小强与那个她的故事
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 16 Accepted Submission(s) : 9
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
有N个正整数,求出他们两两之差的绝对值之和。比如有如下4个数:
4 3 5 2,那么答案为:
|4-3|+|4-5|+|4-2|+|3-5|+|3-2|+|5-2|=10
这对小强来说,简直就是“一块蛋糕”。但是小强还有其他妹子要邂逅,所以将这个问题留给你来搞定了。
Input
首先一个正整数N(1<=N<=100000),代表下面有N个正整数。
接下来输入N个正整数,每个正整数不大于200。
Output
Sample Input
1 4 4 3 5 2
Sample Output
10
Author
【1003代码】
#include <iostream>
using namespace std;
#define LL __int64
int num[205];
int main()
{
int t;
int n, x, i, j;
LL sum;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
memset(num, 0, sizeof(num));
sum = 0;
for (i=0; i<n; i++)
{
scanf("%d", &x);
num[x]++;
}
for (i=1; i<=200; i++)
{
if (num[i]!=0)
{
for (j=i+1; j<=200; j++)
{
if (num[j]!=0)
{
sum += (LL)(j-i)*num[i]*num[j];
}
}
}
}
printf("%I64d\n", sum);
}
return 0;
}然后发现1007是a+b问题,哎,直接copy代码。
然后看到第二题。
生成函数之类的东东吧。自己功力不深,还没办法应用。
于是随便想。由于是等号。所以枚举5z,对于n-5z算出可以得到多少个2y,剩下的就是x了。
O(n)的复杂度就可以出解。后来发现确实是可以用生产函数来做,思路也是差不多这样,不过可能就显得更严谨一些。
W和方程的故事
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
2 0 6
Sample Output
1 5
Author
【1002代码】
#include <iostream>
using namespace std;
int main()
{
int i;
int n, t;
__int64 ct;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
ct = 0;
for (i=0; i*5<=n; i++)
{
ct += (__int64)(n-i*5)/2+1;
}
printf("%I64d\n", ct);
}
return 0;
}之后就打算继续去复习了。但是受不了ACM的诱惑,于是又回来做了。
这道题由于所给数的范围比较小,所以2^20内就可以解决。所以可以先打表。
异样的二进制
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 6 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
第三位是号称WSN(Wo Shen Niu)的WSN帝,别看他名字很WS,可竟然获得了近距离ym LMM的机会,为什么呢? 很简单,因为他是“程序猿”。^-^
因为他知道LMM是CS专业的,对二进制转换非常熟悉,例如13的二进制为1101,因为13=1*2^3+1*2^2+0*2^1+1*2^0,所以他想证明他的魅力,带来了所谓的“负二进制”问题,将基数改为了-2,例如1101,实际上代表着:1*(-2)^3+1*(-2)^2+0*(-2)^2+1*(-2)^0=-3,所以-3的“负二进制”为1101.
同样作为“程序猿”的你,会这个问题么?如果会的说,说不定还能获得ym LMM的机会额,亲。
话说在科大要ym到一个妹纸,比进Final都还难呀。。。
Input
Output
Sample Input
-3 11
Sample Output
1101 11111
Author
【1004代码】
#include <iostream>
using namespace std;
const int maxn = 100000;
struct node
{
int len;
bool by[30];
}num[2*maxn+5];
int value[30];
void dfs(int v, int m, node now, int cur)
{
if (v==m)
{
if (cur<=maxn && cur>=-maxn && num[cur+maxn].len==0)
memcpy(&num[cur+maxn], &now, sizeof(node));
return;
}
now.len++;
now.by[now.len-1] = false;
dfs(v+1, m, now, cur);
now.by[now.len-1] = true;
cur += value[v];
dfs(v+1, m, now, cur);
}
void show(int n)
{
n += maxn;
int i;
for (i=num[n].len-1; i>=0; i--)
{
if (num[n].by[i]) break;
}
if (i<0) i=0;
for ( ; i>=0; i--)
{
if (num[n].by[i]) printf("1");
else printf("0");
}
printf("\n");
}
int main()
{
int i;
value[0] = 1;
for (i=1; i<20; i++) value[i] = value[i-1]*(-2);
for (i=-maxn; i<=maxn; i++) num[i+maxn].len = 0;
node now;
now.len = 0;
dfs(0, 20, now, 0);
int n;
while(scanf("%d", &n)!=EOF)
{
show(n);
}
return 0;
}
看到1008有人很快出了,于是断定为规律题。开始找规律。
然后果真被我找到了。A掉。
三角形
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 6 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
2 1 2
Sample Output
2 8
Author
【1008代码】
#include <iostream>
using namespace std;
const int maxn = 10000;
int x[maxn+5];
int main()
{
int i;
x[1] = 2;
for (i=2; i<=maxn; i++) x[i] = x[i-1] + 6*(i-1);
int t, n;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
printf("%d\n", x[n]);
}
return 0;
}然后决定动手虎视眈眈已久的1009。
只是一道简单的字典树,不过就是有点懒得打。
没想到居然8分钟就被我敲出来了。看来还是有点实力的。
统计难题
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131070/65535K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
注意:本题只有一组测试数据,处理到文件结束.
Output
Sample Input
banana band bee absolute acm ba b band abc
Sample Output
2 3 1 0
Author
【1009代码】
#include <iostream>
using namespace std;
struct node
{
int ct;
int next[26];
}tree[400000];
int tct;
int root;
int new_node()
{
memset(&tree[tct], 0, sizeof(node));
return tct++;
}
void insert(char *s)
{
int rt = root;
int i = 0;
while(s[i]!='\0')
{
tree[rt].ct++;
int tmp = s[i]-'a';
if (tree[rt].next[tmp]==0)
tree[rt].next[tmp] = new_node();
rt = tree[rt].next[tmp];
i++;
}
tree[rt].ct++;
}
int solve(char *s)
{
int rt = root;
int i = 0;
while(s[i]!='\0')
{
int tmp = s[i]-'a';
if (tree[rt].next[tmp]==0) return 0;
rt = tree[rt].next[tmp];
i++;
}
return tree[rt].ct;
}
int main()
{
char str[20];
tct = 0;
root = new_node();
while(gets(str))
{
if (str[0]=='\0') break;
insert(str);
}
while(gets(str))
{
printf("%d\n", solve(str));
}
return 0;
}最后剩下三道题没做。
第一题好像是线段树,前阵子看过,不过还没学到。
序列操作
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 0 Accepted Submission(s) : 0
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Q L R:输出区间[L,R](1<=L,R<=N)中最长连续不下降子序列的长度。
C L R P:将区间[L,R] (1<=L,R<=N)中的每个整数都替换成整数P。
作为USTC的程序精英们,你能很顺利的解决这个问题么?
Input
针对每组测试数据:
首先输入两个正整数N Q(1<=N<=100000,1<=Q<=100000),分别代表序列的长度和操作的次数。
接着输入N个正整数(每个正整数不大于1000)。
最后输入Q行,代表有Q次操作,每行有两种可能的形式:Q L R 或
C L R P。意义如上所示,其中P不大于1000。
注意: L有可能会大于R。
Output
Sample Input
1 6 5 1 2 3 4 5 6 Q 1 6 C 4 3 2 Q 1 3 C 4 5 3 Q 2 5
Sample Output
6 3 4

作者周六在实验室复习期间参与ACM比赛,解决了多个算法题。从水题到复杂问题,涵盖了序列操作、二进制转换、组合数学等多个方面。通过解决一系列问题,展示了作者在ACM竞赛和算法领域的深厚功底。
403

被折叠的 条评论
为什么被折叠?



