太难了…蒟蒻流泪日记
https://www.cnblogs.com/zyysyang/p/11093507.html
2020.2.27 / 中国剩余定理,gcd
非常好的一个博客:
https://blog.csdn.net/acdreamers/article/details/8050018
gcd:
https://vjudge.net/contest/353627#problem/A
#include
using namespace std;
int main()
{
long long a, b, c, d;
long long x[4];
long long y[4];
while (scanf("%lld%lld%lld%lld", &a, &b, &c, &d) != EOF)
{
x[0] = b - a + 1;
x[1] = b / 2 - (a - 1) / 2;
x[2] = b / 1009 - (a - 1) / 1009;
x[3] = b / 2018 - (a - 1) / 2018;
x[2] -= x[3];
x[1] -= x[3];
x[0] -= x[3] + x[2] + x[1];
y[0] = d - c + 1;
y[1] = d / 2 - (c - 1) / 2;
y[2] = d / 1009 - (c - 1) / 1009;
y[3] = d / 2018 - (c - 1) / 2018;
y[2] -= y[3];
y[1] -= y[3];
y[0] -= y[1] + y[2] + y[3];
long long ans = 0;
ans += x[1] * y[2];
ans += x[1] * y[3];
ans += x[2] * y[1];
ans += x[2] * y[3];
ans += x[3] * y[1];
ans += x[3] * y[2];
ans += x[3] * y[3];
ans += x[3] * y[0];
ans += x[0] * y[3];
printf("%lld\n", ans);
}
return 0;
}
中国剩余定理:
https://vjudge.net/contest/353627#problem/D
#include
using namespace std;
typedef long long ll;
const int maxn = 1005;
ll m[maxn], a[maxn], s[maxn];
ll gcd(ll a, ll b)
{
return b ? gcd(b, a % b) : a;
}
void extend_Euclid(ll a, ll b, ll &x, ll &y)
{
if (b == 0)
{
x = 1;
y = 0;
return;
}
extend_Euclid(b, a % b, x, y);
ll tmp = x;
x = y;
y = tmp - (a / b) * y;
}
ll Inv(ll a, ll b)
{
ll d = gcd(a, b);
if (d != 1)
return -1;
ll x, y;
extend_Euclid(a, b, x, y);
return (x % b + b) % b;
}
bool merge(ll a1, ll m1, ll a2, ll m2, ll &a3, ll &m3)
{
ll d = gcd(m1, m2);
ll c = a2 - a1;
if (c % d)
return false;
c = (c % m2 + m2) % m2;
m1 /= d;
m2 /= d;
c /= d;
c *= Inv(m1, m2);
c %= m2;
c *= m1 * d;
c += a1;
m3 = m1 * m2 * d;
a3 = (c % m3 + m3) % m3;
return true;
}
ll CRT(ll a[], ll m[], int n)
{
ll a1 = a[1];
ll m1 = m[1];
for (int i = 2; i <= n; i++)
{
ll a2 = a[i];
ll m2 = m[i];
ll m3, a3;
if (!merge(a1, m1, a2, m2, a3, m3))
return -1;
a1 = a3;
m1 = m3;
}
return (a1 % m1 + m1) % m1;
}
int main()
{
int n;
while (~scanf("%d", &n))
{
for (int i = 1; i <= n; i++)
{
scanf("%lld%lld", &m[i], &a[i]);
}
cout << CRT(a, m, n) << endl;
}
return 0;
}
特别的floyed,不记录路径长度,记录最短路径上的最长距离;
https://vjudge.net/contest/353626#problem/D
#include
using namespace std;
const int MAXN=210;
pair<int,int>p[MAXN];
double dis(pair<int,int>p1,pair<int,int>p2)
{
return sqrt((double)(p1.first-p2.first)*(p1.first-p2.first)+(p2.second-p1.second)*(p2.second-p1.second));
}
double dist[MAXN][MAXN];
int main()
{
int n;
int x,y;
int iCase=0;
while(scanf("%d",&n)==1&&n)
{
iCase++;
printf("Scenario #%d\n",iCase);
for(int i=0;i<n;i++)
{
scanf("%d%d",&x,&y);
p[i]=make_pair(x,y);
}
for(int i=0;i<n;i++)
for(int j=i;j<n;j++)
{
if(i==j)dist[i][j]=dis(p[i],p[j]);
else dist[j][i]=dist[i][j]=dis(p[i],p[j]);
}
for(int k=0;k<n;k++)
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(dist[i][j]>max(dist[i][k],dist[k][j]))
dist[i][j]=max(dist[i][k],dist[k][j]);
printf("Frog Distance = %.3f\n\n",dist[0][1]);
}
return 0;
}
正常的floyed判断负环
https://vjudge.net/contest/353626#problem/E
#include
#include
# define inf 99999999
int map[510][510];
int book[510],dis[510];
int main()
{
int p,n,m,i,j,k,w,a,b,c,f;
int s[210],e[210],t[210];
scanf("%d",&p);
while(p--)
{
scanf("%d%d%d",&n,&m,&w);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(i==j)
map[i][j]=0;
else
map[i][j]=inf;
}
for(i=1;i<=m;i++)//输入正权边
{
scanf("%d%d%d",&a,&b,&c);
if(map[a][b]>c)
{
map[a][b]=c;
map[b][a]=c;
}
}
for(i=1;i<=w;i++)//输入负权边
{
scanf("%d%d%d",&a,&b,&c);
map[a][b]=-c;
}
f=0;
for(k=1;k<=n;k++)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
if(map[i][j]>map[i][k]+map[k][j])
{
map[i][j]=map[i][k]+map[k][j];
}
if(map[i][i]<0)
{
f=1;
break;
}
}
if(f==1) //若找到就跳出,否则会超时
break;
}
if(f==1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
还有一个死活不会的题
https://vjudge.net/contest/353626#problem/F
http://acm.csust.edu.cn/contest/70/
A:双向冒泡
B:暴力枚举
鬼知道为啥从贪心写到dfs…
C:
https://vjudge.net/contest/351262#problem/D
题目意思不好理解
https://vjudge.net/contest/351262#problem/E
固定一个枚举另一个然后再记录最小值
等会有场cf的div2,希望不爆0…
…A了一题A
明天补题,烦啊…
2020.3.2/基础学科啊…还有最小生成树,最短路什么的算法根本都不熟悉
难顶啊
2020。3.8/混了好多天。。。
2020.3.19/数论
https://blog.csdn.net/C202044zxy/article/details/103217365
欧拉降幂公式
https://vjudge.net/contest/353627#problem/H
题目,数幂塔
https://blog.csdn.net/wanghandou/article/details/53413032
并查集应用