# zcmu之水题来一波~

### 1036: Shepherd

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 296  Solved: 76
[Submit][Status][Web Board]

## Description

Hehe keeps a flock of sheep, numbered from 1 to n and each with a weight wi. To keep the sheep healthy, he prepared some training for his sheep. Everytime he selects a pair of numbers (a,b), and chooses the sheep with number a, a+b, a+2b, … to get trained. For the distance between the sheepfold and the training site is too far, he needs to arrange a truck with appropriate loading capability to transport those sheep. So he wants to know the total weight of the sheep he selected each time, and he finds you to help him.

## Input

There’re several test cases. For each case:
The first line contains a positive integer n (1≤n≤10^5)---the number of sheep Hehe keeps.
The second line contains n positive integer wi(1≤n≤10^9), separated by spaces, where the i-th number describes the weight of the i-th sheep.
The third line contains a positive integer q (1≤q≤10^5)---the number of training plans Hehe prepared.
Each following line contains integer parameters a and b (1≤a,b≤n)of the corresponding plan.

## Output

For each plan (the same order in the input), print the total weight of sheep selected.

## Sample Input

5 1 2 3 4 5 3 1 1 2 2 3 3

## Sample Output

15 6 3

【分析】注意特判一下b==0的情况（虽然题上说了b>=1了）

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn=1e5+5;
int w[maxn];
int main()
{
int n;
while(~scanf("%d",&n))
{
long long sum=0;
memset(w,0,sizeof(w));
for(int i=0;i<n;i++)
{
scanf("%d",&w[i]);
sum+=w[i];
}
int q;
scanf("%d",&q);
while(q--)
{
int a,b;
long long ans=0;
scanf("%d%d",&a,&b);
if(b==0)
ans=w[a-1];
else if(b==1&&a==1)
ans=sum;
else
for(int i=a-1;i<n;i+=b)
ans+=w[i];
printf("%lld\n",ans);
}
}
return 0;
} 

## 1112: 对于数字的强迫症

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 473  Solved: 293
[Submit][Status][Web Board]

111 991 10001 0

## Sample Output

12121 91091 1010101

#include<bits/stdc++.h>
using namespace std;
char s1[1005];
int main()
{
while(cin>>s1&&s1[0]!='0')
{
int l=strlen(s1);
for(int i=0;i<l-1;i++)
{
cout<<s1[i];
if(s1[i]==s1[i+1]){
if(s1[i]=='9')cout<<"10"; /注意对9的讨论
else printf("%c",s1[i]+1);
}
}cout<<s1[l-1]<<endl;
}
return 0;
}


## 1137: 最后一次队内赛的a+b

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1204  Solved: 410
[Submit][Status][Web Board]

1 1 2 3

## Sample Output

11 23

【分析】emmm很烦，用了strcat()函数，但是没有考虑连接后会溢出的问题o(╥﹏╥)o

strcat函数常见的错误就是数组越界，即两个字符串连接后，长度超过第一个字符串数组定义的长度，导致越界

## 1278: Sequence（哈希）

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 675  Solved: 202
[Submit][Status][Web Board]

## Description

There is a sequence of n numbers. And in this sequence, there is only one number appears twice.
Can you tell me which number appears twice.

## Input

There are multiple test cases in the input file.
In each case the first line contains an integer n (2<=n<=1000) — the size of the sequence.
The second line contains n integers a1, a2, ..., an (1<=ai<=1000) — the elements of the sequence.

## Output

For each case print a single line with the number.

2

1 1

4

1 2 2 3

1

2

## Source

xzy

【分析】哈希数组，统计每个数字出现的次数即可。

## 1279: Sort photos（读题）

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 537  Solved: 141
[Submit][Status][Web Board]

## Description

Imagine you have a pile of n photos. Some of them are faced upwards and the others faced downwards. Your goal is to sort them so that all the photos are faced the same direction. The only operation you are allowed to do is to take any amount of the photos if their direction is same to the other direction. Write the program that calculates the minimum number of such operations needed to complete the sorting goal.

## Input

There are multiple test cases in the input file.
For each test case, the first line is n (0<n<10^5) - the number of photos.
The second line is n characters "D" - faced down or "U" - faced up.

## Output

For each test case there is a single integer number - minimal number of flip operations required to sort the photos pile.

5

UUDUU

4

UDUD

1

2

## Source

xzy

【分析】注意读题，题目要求的是最小翻转次数的前提是相邻的两个字符是不一样的时候进行翻转，而不是任意翻转，不能不管相邻的两个字符的情况就直接计算两个字符出现的次数然后求最小。

## 1653: 这样真的好么（*^*）

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 255  Solved: 129
[Submit][Status][Web Board]

## Input

多组测试，请处理到文件末尾，输入的格式是，第一行是n,k(k<n<=100)接下来n个数，表示气球的编号。

4 2

2 1 2 2

6 2

2 2 1 1 1 2

1

0

## HINT

样例解释:1 由 2 1 2 2 --->1 1 2 2

【分析】水题。因为编号是1~k，每一个都要有。而k整除n，所以求平均每个数的数量为n/k，所以只要统计比这个数小的与它的差值和就好了。

【代码】

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int a[105],b[105];
int main()
{
int n,k;
while(~scanf("%d%d",&n,&k))
{
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
b[a[i]]++;
}
int ans=n/k,cnt=0;
for(int i=1;i<=k;i++)
{
if(b[i]<ans)
cnt+=ans-b[i];
}
cout<<cnt<<endl;
}
}

### 1654: 据说题目里藏着某人的QQ号\(^o^)/~

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 333  Solved: 125
[Submit][Status][Web Board]

d

5

## HINT

A(a):6

B(b):9

C(c):0

D(d):5

E(e):8

F(f):1

G(g):9

H(h):4

I(i):6

J(j):3

K(k):2

L(l):34

M(m):67

N(n):67

O(o):78967

P(p):345

Q(q):454

R(r):434

S(s):345

T(t):12

U(u):978

V(v):563

W(w):34

X(x):34

Y(y):5885

Z(z):45

【分析】水题

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int str[]={6,9,0,5,8,1,9,4,6,3,2,34,67,67,78967,345,454,434,345,12,978,563,34,34,5885,45};
int main()
{
string s;
while(cin>>s)
{
long long sum=1;
int len=s.length();
for(int i=0;i<len;i++)
{
sum*=str[tolower(s[i])-'a'];
sum%=751492854;
}
cout<<sum<<endl;
}
return 0;
}

## 1655: 某人好想AC哦~

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 220  Solved: 106
[Submit][Status][Web Board]

woyaowwwaaaac wa

woyaoac

## HINT

第一步：woyaowwwaaaac--->woyaowwaaac

第二步：woyaowwaaac---->woyaowaac

【分析】水题。string相关函数的使用

【代码】

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
string s;
while(cin>>s)
{
string str;
cin>>str;
int len=str.length();
while(s.find(str)!=string::npos)
{
int pos=s.find(str);
s.erase(s.begin()+pos,s.begin()+pos+len);
}
cout<<s<<endl;
}
return 0;
}

## 1657: O(∩_∩)O哈！

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 322  Solved: 130
[Submit][Status][Web Board]

4

zcc 59

ayer 90

huhu 90

zhang 0

## Sample Output

ayer 90

huhu 90

zcc 59

zhang 0

【分析】结构体排序，重写cmp函数就好。水题

【代码】

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
struct node{
string name;
int score;
}a[105];
bool cmp(node x,node y)
{
return x.score!=y.score?x.score>y.score:x.name<y.name;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
cin>>a[i].name>>a[i].score;
sort(a,a+n,cmp);
for(int i=0;i<n;i++)
cout<<a[i].name<<" "<<a[i].score<<endl;
}
return 0;
}

## 1658: O__O "… 就是那道中文题

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 458  Solved: 139
[Submit][Status][Web Board]

5 4

1 2 3 4 5

1 1

1 2

1 5

2 4

## Sample Output

1

1

3

3

【分析】计算前缀和。注意用scanf和printf，不然会超时

【代码】

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=1e5+5;
int sum[maxn];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(sum,0,sizeof(sum));
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
sum[i]=x+sum[i-1];
}
while(m--)
{
int x,y;
scanf("%d%d",&x,&y);
int l=y-x+1;
printf("%d\n",(sum[y]-sum[x-1])/l);
}
}
return 0;
}

## 1663: 字符识别？

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 103  Solved: 61
[Submit][Status][Web Board]

## Description

.*.  ***  ***
.*.  ..*  ..*
.*.  ***  ***
.*.  *..  ..*
.*.  ***  ***

## Output

输出应包含一行，即识别出的各个字符。

## Sample Input

3
.*..***.***.
.*....*...*.
.*..***.***.
.*..*.....*.
.*..***.***.

## Sample Output

123

【分析】找规律。会发现只有第4行3个数字是不同的。通过求余确定位置从而确定数字。

【代码】

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
using namespace std;
int main(){
int n,i,j,k;
while(~scanf("%d",&n))
{
getchar();
string s1,s2;
for(i=0;i<5;i++)
{
if(i==3)cin>>s1;
else cin>>s2;
}
for(j=0;j<n*4;j++)
{
if(s1[j]=='*')
{
if(j%4==1)printf("1");
else if(j%4==0)printf("2");
else if(j%4==2)printf("3");
}
}
printf("\n");
}
return 0;
}

## 1672: 憋说话，好好算

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 512  Solved: 196
[Submit][Status][Web Board]

2 2

1 1 0 0 0 0

1 0 1 0 0 1

## Sample Output

2

【分析】简单题，模拟就好。注意多组测试数据，不然会wa的

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,ans=0;
while(~scanf("%d%d",&n,&m))
{
ans=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
if(x+y+z>=2)ans++;
}
}
cout<<ans<<endl;
}

return 0;
}

## 1674: 买买买

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 648  Solved: 199
[Submit][Status][Web Board]

1 1 2

4 2 1

## Sample Output

wangwangwang

2 1 1

【分析】水题。算算就出来了

【代码】

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
long long x,y,z;
while(~scanf("%lld%lld%lld",&x,&y,&z))
{
long long a,b,c;
a=x+y+2*z;
b=x+y-2*z;
c=x-y;
if(a<0||b<0||c<0||a%4!=0||b%4!=0||c%2!=0)printf("wangwangwang\n");
else printf("%lld %lld %lld\n",a/4,b/4,c/2);
}
return 0;
}

## 1109: 胥哥的DOTA（水题）

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 371  Solved: 179
[Submit][Status][Web Board]

## Description

集训队的孩子们一定听过一个叫XZY的编程大神吧，其实这不仅是编程大神，而且是DOTA大神，曾带这一群DOTA菜鸟虐爆电脑，可是这个DOTA大神最近竟然要说要戒DOTA了，据说还把DOTA给删了（显然是假的。。。。）。经过本人多天的调查原因是这样的：一天胥哥正在中路和别人兴致勃勃的SOLO中，在即将要赢，还未赢的关键时刻，突然天空飞来一只神箭（白虎的箭），将他射中，从杀人到被杀的感觉使他大叫“坑爹！！！剧本不是这样的呀！！”，最后总结得出没有把计算清楚！！所以为了以后能更好的DOTA，他决定先去学ACM，学好算法！！现在正好有道关于这类的题目希望大家能帮他解决！！题目是这样的:

## Input

有多组数据，每组数据的第一行有两个数n（0<n<1000），m(1=<m<=100)，代表直线的长度和白虎的数量，

10 2

4 6

6 10

## Sample Output

12

【分析】水题，不要想太多，数据不大，循环过去就好了。

【代码】

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=1e3+5;
struct node{
int dis;
int p;
}a[maxn];
bool cmp(node x,node y)
{
return x.p<y.p;
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
for(int i=0;i<m;i++)
scanf("%d%d",&a[i].dis,&a[i].p);
int minn=999999999;
for(int i=0;i<=n;i++)
{
int sum=0;
for(int j=0;j<m;j++)
sum+=fabs(i-a[j].dis)*a[j].p;
minn=min(minn,sum);
}
printf("%d\n",minn);
}
}

10-19 32
12-16 229

09-13 115
07-29 69
10-15 179
11-26 604
10-30 68
08-23 217
03-06 83
09-03 620
02-29 1304
09-10 283