T1&T2&T3&T4&T5
全部暴力啊
数据这么小~
心态崩爽
T1
题目:
A+B
解题思路:
空
Accepted code:
/*
ID: halo_mi1
TASK: test
LANG: C++
*/
#include <cstdio>
#include <cstdlib>
using namespace std;
int a, b;
int main () {
freopen ("test.in", "r", stdin);
freopen ("test.out", "w", stdout);
scanf ("%d %d", &a, &b);
printf ("%d\n", a + b);
}
T2
题目大意:
有两个长度为1 ~ 6的名字,名字由’A’ ~ ‘Z’组成
将’A’定义为1,'B’定义为2,,'C’定义为3……'Z’定义为26
将第一个名字的积mod(%)47和第二个名字的积mod(%)47
若相等输出 ‘GO’ 否则输出 'STAY’
解题思路:
直接暴力模拟
Accepted code:
/*
ID: halo_mi1
TASK: ride
LANG: C++
*/
#include<cstdio>
#define fre(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
using namespace std;
int UFO = 1, Team = 1; char c;
int main() {
fre(ride)
while ((c = getchar()) != '\n')
UFO *= (c - 64);
while ((c = getchar()) != '\n')
Team *= (c - 64);
if (UFO % 47 == Team % 47)
puts("GO"); else puts("STAY");
fclose(stdin); fclose(stdout);
return 0;
}
T3
题目:
对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少。在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人。然而,在任何一群朋友中,有些人将送出较多的礼物(可能是因为有较多的朋友),有些人有准备了较多的钱。给出一群朋友,没有人的名字会长于 14 字符,给出每个人将花在送礼上的钱,和将收到他的礼物的人的列表,请确定每个人收到的比送出的钱多的数目。
解题思路:
map + 暴力
Accepted code:
/*
ID: halo_mi1
TASK: gift1
LANG: C++
*/
#define fre(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#include<map>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
map<string, int> ans;
int N, money, num;
string name[11], s;
int main() {
fre(gift1);
scanf("%d", &N);
for (int i = 1; i <= N; i++)
cin>>name[i];
for (int i = 1; i <= N; i++) {
cin>>s;
scanf("%d %d", &money, &num);
if (!num) continue;
money -= money % num;
ans[s] -= money;
for (int i = 1; i <= num; i++) {
cin>>s;
ans[s] += money / num;
}
}
for (int i = 1; i <= N; i++)
cout<<name[i], printf(" %d\n", ans[name[i]]);
}
T4
题目大意:
要求计算每个月的十三号落在周一到周日的次数。给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400.
解题思路:
还是暴力
(之前做了,码风好丑)
Accepted code:
/*
ID: halo_mi1
TASK: friday
LANG: C++
*/
#define fre(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#include<cstdio>
#include<algorithm>
using namespace std;
int ans,n,zj,l,x,y,a[8];
int r[13]={0,31,0,31,30,31,30,31,31,30,31,30,31};
int main()
{
fre(friday);
scanf("%d",&n);
for (int i=1900;i<1900+n;i++)
{
bool pd=0;
if(i%4==0)
{
if(i%100!=0) pd=1;
if(i%100==0&&(i/100)%4==0)
pd=1;
}
if(pd==1)
r[2]=29; else r[2]=28;
for (int j=1;j<=12;j++)
{
for (int k=1;k<=r[j];k++)
{
zj++;
if (zj==8) zj=1;
if (k==13) a[zj]++;
}
}
}
printf("%d %d",a[6],a[7]);
for (int i=1;i<=5;i++) printf(" %d",a[i]);
return printf("\n")&0;
}
T5
题目:
假如你要在一些点打破项链,展开成一条直线,然后从一端开始收集同颜色的珠子直到你遇到一个不同的颜色珠子,在另一端做同样的事(颜色可能与在这之前收集的不同)。 确定应该在哪里打破项链来收集到最大数目的珠子。
例如,在图片 A 中的项链中,在珠子 9 和珠子 10 或珠子 24 和珠子 25 之间打断项链可以收集到8个珠子。
白色珠子什么意思?
在一些项链中还包括白色的珠子(如图片B) 所示。
当收集珠子的时候,一个被遇到的白色珠子可以被当做红色也可以被当做蓝色。
表现含有白珠项链的字符串将会包括三个符号 r , b 和 w 。
写一个程序来确定从一条被给出的项链可以收集到的珠子最大数目。
解题思路:
暴力啊啊啊啊
Acceped code:
#include<cstdio>
#include<algorithm>
using namespace std;
int ans, n;
char s[1000], c[1000];
void change(int x) {
for (int i = 1; i <= n; i++)
s[i] = c[(i + x - 1) % n + 1];
}
int calc() {
char F, L;
int first = 1, last = n;
int ans_f = 0, ans_l = 0;
while (s[first] == 'w')
first++, ans_f++;
F = s[first];
while (s[first] == F || s[first] == 'w')
first++, ans_f++;
while (s[last] == 'w')
last--, ans_l++;
L = s[last];
while (s[last] == L || s[last] == 'w')
last--, ans_l++;
return (ans_f + ans_l > n ? n : ans_f + ans_l);
}
int main() {
scanf("%d", &n); char C;
while ((C = getchar()) != '\n');
for (int i = 1; i <= n; i++) c[i] = getchar();
for (int i = 1; i <= n; i++) {
change(i);
ans = max(ans, calc());
}
printf("%d", ans);
return 0;
}
总结:
暴力主要看细节