题目链接:
题号 | 标题 | 已通过代码 |
A | ||
B | ||
C | ||
D | ||
E | ||
F | ||
G | ||
H | ||
I | ||
J |
A:使用double高精度,坐标系内两点之间距离 sqrt(pow(x1-x2),pow(y1-y2))
判断目标点和 l1+l2 的关系,大的话,结果就是 sqrt(x*x + y*y) - l1 - l2
判断目标点和 l1-l2 的关系,小的话,结果就是 abs(l1 - l2) - sqrt(x*x + y*y)
目标点在范围内就输出0.00000000
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
double l1, l2, x, y,len;
scanf("%lf%lf%d", &l1, &l2, &t);
getchar();
while (t--)
{
cin >> x >> y;
if (sqrt(x*x + y*y) > l1 + l2)
{
printf("%.8f\n",sqrt(x*x + y*y) - l1 - l2 );
}
else if (sqrt(x*x + y*y) < abs(l1 - l2))
{
printf("%.8f\n", abs(l1 - l2) - sqrt(x*x + y*y));
}
else printf("0.00000000\n");
}
return 0;
}
G:注释都写在代码里了 直接看代码
#include<iostream>
using namespace std;
int yin[1000005];//yin[i]代表的是i的因子个数
int ans[1000005];//ans[i]代表含有i个因子个数的值
void shai()
{
for (int i = 1; i < 1000004; i++) //i代表因子个数
{
for (int j = i; j < 1000004; j += i) //j是i倍数 不断给1~1000000添加每个数的因子
{
yin[j]++;//是i的倍数的数 因子个数都加1
}
if (ans[yin[i]])//如果ans[i]不为零了,那么说明这个数不是因子个数为i的情况下的最小值,就跳过
continue;
else//如果这个数之前没有被赋值 说明是最小的
ans[yin[i]] = i;
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);//输入很多的时候 关闭流同步
shai();
int t, n;
cin >> t;
while (t--)
{
cin >> n;
if (ans[n])
cout << ans[n] << "\n";
else
cout << -1 << "\n";
}
return 0;
}
I:写的比较乱,刚开始想简单了,这算是我第一次写dfs了,纪念一下,第一次只写了向下,然后测试样例发现不对,又想到了还需要判断光线方向,就在dfs里加一个变量h代表方向
#include<bits/stdc++.h>
using namespace std;
int n, m,flag;
char a[510][510];
void dfs(int x,int y,int k,int h)
//x,y代表坐标 ,k代表是否出界,h代表方向
//上下左右 1234
{
if (k==0)
{
return;
}
if ((y>m)||y == 0||x==0) {
cout << -1 << "\n";
k = 0;
return;
}
if (x > n) {
cout << y << "\n";
return;
}
else {
if (a[x][y] == '.'&&h == 2) //下
dfs(x + 1, y, 1, 2);
else if (a[x][y] == '/'&&h == 2)
dfs(x, y - 1, 1, 3);
else if ((a[x][y] == 92) && h == 2)
dfs(x, y + 1, 1, 4);
else if (a[x][y] == '.'&&h == 1) //上
dfs(x - 1, y, 1, 1);
else if (a[x][y] == '/'&&h == 1)
dfs(x, y + 1, 1, 4);
else if (a[x][y] == 92 && h == 1)
dfs(x, y - 1, 1, 3);
else if (a[x][y] == '.'&&h == 3) //左
dfs(x, y - 1, 1, 3);
else if (a[x][y] == '/'&&h == 3)
dfs(x + 1, y, 1, 2);
else if (a[x][y] == 92 && h == 3)
dfs(x - 1, y, 1, 1);
else if (a[x][y] == '.'&&h == 4) //右
dfs(x, y + 1, 1, 4);
else if (a[x][y] == '/'&&h == 4)
dfs(x - 1, y, 1, 1);
else if (a[x][y] == 92 && h == 4)
dfs(x + 1, y, 1, 2);
}
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++)
cin >> a[i][j];
}
for (int i = 1; i <=m; i++)
{
dfs(1,i,1,2);
}
return 0;
}
J:刚开始想复杂了,又是求排列,又是求组合,做了一个半小时,头都炸了,后来放弃了,做完i题又回来看了看,发现ac的人六百多,肯定没我想的那么复杂啊,又回头看了看,其实就是3^m,快速幂模版套上,a了。
#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
#define ll long long
ll qmi(ll a, ll b, ll p)
{
ll res = 1;
while (b)
{
if (b & 1) res = (res * a) % p;
a = (a * a) % p;
b = b >> 1;
}
return res;
}
int main()
{
ll m, ans, x = 2;
while (cin >> m)
{
ans = qmi(3, m, mod);
cout << ans << endl;
}
return 0;
}