usaco水题

黑色星期五
纯模拟都能过

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<cstdio>
using namespace std;
int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};int t=0,n,c[999999];
int main(){
scanf("%d",&n);
for(int i=1900;i<=n+1900-1;i++){
if(i%4==0&&i%100!=0||i%400==0){
for(int j=0;j<=11;j++)
{
for(int k=1;k<=a[j];k++)
{
t++;
if(k==13)c[t%7]++;
}
}
}
else{
for(int j=0;j<=11;j++)
{
for(int k=1;k<=b[j];k++)
{
t++;
if(k==13)c[t%7]++;
}
}


}

}printf("%d ",c[6]);
printf("%d ",c[0]);
for(int i=1;i<=5;i++)
{
printf("%d ",c[i]);
}

}

贪婪的送礼者

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<cstdio>
#include<map>
#include<string>
#include<iostream>
using namespace std;
map <string,int> f;
string a[999],b;int n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b;
int x,y;
scanf("%d%d",&x,&y);
if(y!=0)
f[b]-=x/y*y;
for(int i=1;i<=y;i++)
{
cin>>b;
f[b]+=x/y;
}
}
for(int i=1;i<=n;i++){
cout<<a[i]<<" "<<f[a[i]]<<endl;
}
}

直接暴力枚举,然后用结构体记下来,再排个序输出就行了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<cstdio>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int n,t=0;
struct str{
int a,b;
double c;
}x[999999];
int comp(const str &a,const str &b){
if(a.c<b.c)return 1;
return 0;
}
int gcd(int x,int y){
if(x%y==0)
return y;
return gcd(y,x%y);
}

int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
if(gcd(i,j)==1)
x[++t].a=i,x[t].b=j,x[t].c=1.0*i/j;

}
sort(x+1,x+t+1,comp);
printf("0/1\n");
for(int i=1;i<=t;i++)
{
printf("%d/%d\n",x[i].a,x[i].b);
}

}

三值的排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<cstdio>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int n,t=0,a[99999];
int q=0,s[999999],p[2999][2999];

int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
s[a[i]]++;
}
for(int i=1;i<=s[1];i++)
p[1][a[i]]++;
for(int i=s[1]+1;i<=n-s[3];i++)
p[2][a[i]]++;
for(int i=n-s[3]+1;i<=n;i++)
p[3][a[i]]++;
printf("%d",s[1]-p[1][1]+s[3]-p[3][3]-min(p[1][3],p[3][1])) ;//why,我不知道

}

阶乘
这个题只要记下最后几位不是零的数就行了,我记了六位,其实没必要记那么多,然会最后把零去除输出就行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<cstdio>
#include<iostream>
#include<cstring>
#define ll long long
using namespace std;
int n;
int main(){
scanf("%d",&n);int s=1;
for(int i=1;i<=n;i++)
{
while(s%10==0)
s/=10; s=s*i%1000000;
}
int x=s;
while(1){
if(x%10!=0)
{
printf("%d",x%10);
return 0;
}
x=x/10;
}

return 0;
}

滑雪程序设计
枚举一个山的最小高度,最大高度就是最小高度+17
然后算出价值取min

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<cstdio>
#include<map>
#include<string>
#include<iostream>
using namespace std;
int ans=99999999,s;
int n,a[999999];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=0;i<=83;i++)
{s=0;
for(int j=1;j<=n;j++)
if(a[j]<i)
{
s=s+(a[j]-i)*(a[j]-i);
}
else if(a[j]>i+17)
{
s=s+(a[j]-i-17)*(a[j]-i-17);
}
ans=min(ans,s);
}

printf("%d",ans);
}

最近的文章

跳石头

二分答案加贪心和之前一个丢瓶盖一样,对去几个石子二分,去多了就取大了,去少了就取小了 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 …

于  二分答案 贪心 继续阅读
更早的文章

书的复制

这个题就是一个动归,和乘积最大一样,处理前缀和,枚举当前位置和划分层数,找最大的时间,取最小值12345678910111213141516171819202122232425262728293031323334353637383940#include&lt;cstdio&gt;#include&l …

于  dp 继续阅读