36进制
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
int main()
{
string str;
cin >> str;
LL res = 0, k = 0;
for (int i = str.size() - 1; i >= 0; i -- )
{
char c = str[i];
int t;
if (c >= 'A' && c <= 'Z') t = 10 + c - 'A';
else t = c - '0';
res += t * pow(36, k);
k ++ ;
}
cout << res << endl;
return 0;
}
瓷砖样式
笑死,不会。我只会蒙德里安的梦想呜呜呜
希尔伯特曲线
#include <stdio.h>
long long f(int n, int x, int y) {
if (n == 0) return 1;
int m = 1 << (n - 1);
if (x <= m && y <= m) {
return f(n - 1, y, x);
}
if (x > m && y <= m) {
return 3LL * m * m + f(n - 1, m - y + 1, m * 2 - x + 1); // 填空
}
if (x <= m && y > m) {
return 1LL * m * m + f(n - 1, x, y - m);
}
if (x > m && y > m) {
return 2LL * m * m + f(n - 1, x - m, y - m);
}
}
int main() {
int n, x, y;
scanf("%d %d %d", &n, &x, &y);
printf("%lld", f(n, x, y));
return 0;
}
发现环
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int N = 100010;
int n;
int d[N];
vector<int> g[N];
vector<int> ans;
void topsort()
{
queue<int> q;
for (int i = 1; i <= n; i ++ )
if (d[i] == 1) q.push(i), d[i] -- ;
while (q.size())
{
auto t = q.front();
q.pop();
for (auto& x : g[t])
if (-- d[x] == 1)
q.push(x);
}
for (int i = 1; i <= n; i ++ )
if (d[i] == 2)
ans.push_back(i);
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++ )
{
int a, b;
scanf("%d%d", &a, &b);
g[a].push_back(b), g[b].push_back(a);
d[a] ++ , d[b] ++ ;
}
topsort();
sort(ans.begin(), ans.end());
for (auto& t : ans)
printf("%d ", t);
return 0;
}
对局匹配
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=1e5+1100;
int a[N],book[N];
int main()
{
int n,k,x,p;
scanf("%d %d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
int ans=0;//匹配对数
memset(book,0,sizeof(book));
for(int i=1;i<=n;i++)
{
if(book[i])
continue;
x=a[i]+k;
//p表示区间[i+1,n]内第一个>=x的下标
p=lower_bound(a+1+i,a+1+n,x)-a;
if(p!=n+1&&a[p]==x)
{
a[p]=-1;
book[p]=1;
ans++;
}
}
//匹配成对的只留其一即可
printf("%d\n",n-ans);
return 0;
}
铁路建设
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 25;
long double d[N], sum;
int main()
{
int n, m;
scanf("%d%d", &n, &m);
sum = m;
while (m -- )
{
int a, b;
cin >> a >> b;
d[a] ++ , d[b] ++ ;
}
for (int i = 1; i <= n; i ++ )
printf("%.12Lf\n", (long double)(2 * sum * 1.0) / d[i]);
return 0;
}