- 第十一届
t1
ans=624
t2 ans=2481215
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
int res=0;
for(int i=1;i<=2020;i++)
for(int j=1;j<=2020;j++)
{
if(__gcd(i,j)==1) res++;
}
cout<<res<<endl;
return 0;
}
t3 ans=761
找斜行的规律
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
int d=4,s=1;
for(int i=2;i<=20;i++)
{
s+=d;
d+=4;//每次后面的数和前面的数的公差都加4
}
cout<<s<<endl;
}
t4
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
//判断这一年是不是闰年
int judge(int y)
{
if((y%100!=0&&y%4==0) || y%400==0)return 1;
else return 0;
}
int main()
{
int ans=0;
int w=6;//从周六开始的
for(int y=2000;y<=2020;y++)
for(int m=1;m<=12;m++)
for(int d=1;d<=month[m]+((m==2)?judge(y):0);d++, w=w%7+1;)
{
//星期几的改变一定不能放在这里,这样星期几是错误的
ans++;
if(d==1 || w==1) ans++;
if(y==2020&&m==10&&d==1)
{
cout<<ans<<endl;
break;
}
}
return 0;
}
- 第十二届
t4货物摆放 ans=2430
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long LL;
int main()
{
LL n;
cin>>n;
vector<LL>d;
for(LL i=1;i<=n/i;i++)
{
if(n%i==0)
{
d.push_back(i);
if(n/i!=i)d.push_back(n/i);
}
}
int res = 0;
for(auto a:d)
for(auto b:d)
for(auto c:d)
if(a*b*c==n)res++;
cout<<res<<endl;
}
t5最短路问题,有错误
//最短路问题
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=2050,M=2*N;
int h[N],e[M],w[M],ne[M],idx;
int dist[N];
bool st[N];
int n=2021;
void add(int a,int b,int c)
{
e[idx]=b;
w[idx]=c;
ne[idx]=h[a];
h[a]=idx++;
}
void dijkstra()
{
memset(dist,0x3f,sizeof dist);
dist[1]=0;
// st[1]=true;
for(int i=1;i<=n-1;i++)
{
int t=-1;
for(int j=1;j<=n;j++)
{
if(st[j]==false && (t==-1||dist[j]<dist[t]))
t=j;
}
st[t]=true;
for(int j=h[t];j!=-1;j=ne[j])
{
int q=e[j];
dist[q]=min(dist[q],dist[t]+w[j]);
}
}
}
int main()
{
memset(h,-1,sizeof h);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(i==j)add(i,j,0);
else
{
if(abs(j-i)<=21)
{
add(i,j,(i*j)/__gcd(i,j));
}
}
}
dijkstra();
cout<<dist[2021]<<endl;
}