[NOIP2013D1]
T1
Problem
Solution
感觉我写的也不是正解。。。
我是先找出每个循环节的长度l。。。然后用快速幂求出10 ^ k % l的值。。
Code
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
ll read()
{
ll x = 0; int zf = 1; char ch;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * zf;
}
ll T[1000005];
int main()
{
ll n = read(), m = read(), k = read(), x = read();
T[0] = x;
int l;
for (int i = 1; i <= n; i++)
{
x = (x + m) % n;
T[i] = x;
if (T[i] == T[0])
{
l = i;
break;
}
}
ll ans = 1, now = 10;
while (k > 0)
{
if (k % 2 == 1) ans = ans * now % l;
now = now * now % l;
k /= 2;
}
printf("%d\n", T[ans]);
}
T2
Problem
Solution
首先可以证明当Ai在A中大小排名和Bi在B中大小排名相等时,其差的平方时最小的。。
因此只要控制排名相等就可以了。。所以先排序,然后建立一个排名在A中和B中位置的关系。。。最后用归并排序求逆序对。。
证明(两个数):设A中两个数a < b,B中两个数c < d
ans1 = (a - c) ^ 2 + (b - d) ^ 2 = a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 - 2 * a * c - 2 * b * d
ans2 = (a - d) ^ 2 + (b - c) ^ 2 = a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 - 2 * a * d - 2 * b * c
又因为a * c + b * d - a * d - b * c = (a - b) * (c - d) > 0
所以ans1 < ans2
Code
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
ll read()
{
ll x = 0; int zf = 1; char ch;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * zf;
}
ll ans = 0;
int X[100005], T[100005];
struct node
{
int val, id;
}a[100005], b[100005];
int cmp(node x, node y)
{
return x.val < y.val;
}
void merge(int xl, int xr, int yl, int yr)
{
int l = xl, r = yr, now = l;
while (xl <= xr && yl <= yr)
{
if (X[xl] <= X[yl]) T[now++] = X[xl++];
else
{
T[now++] = X[yl++];
ans = (ans + xr - xl + 1) % 99999997;
}
}
while (xl <= xr) T[now++] = X[xl++];
while (yl <= yr) T[now++] = X[yl++];
for (int i = l; i <= r; i++) X[i] = T[i];
}
void mergesort(int l, int r)
{
if (l == r) return;
int mid = (l + r) >> 1;
mergesort(l, mid);
mergesort(mid + 1, r);
merge(l, mid, mid + 1, r);
}
int main()
{
int n = read();
for (int i = 1; i <= n; i++)
a[i].val = read(), a[i].id = i;
for (int i = 1; i <= n; i++)
b[i].val = read(), b[i].id = i;
sort(a + 1, a + n + 1, cmp);
sort(b + 1, b + n + 1, cmp);
for (int i = 1; i <= n; i++)
X[b[i].id] = a[i].id;
mergesort(1, n);
printf("%lld\n", ans);
}
[NOIP2013D1]的更多相关文章
随机推荐
- ColumnStore完整验证指南之安装与启动停止
官方文档https://mariadb.com/kb/en/library/mariadb-columnstore/ 推荐使用最新1.2.x最新版本. 先决条件 yum -y install boos ...
- java.lang.IllegalStateException: getWriter() has already been called for this response
出现此异常的三种可能: 1.通过response.reset(); 刷新可能存在一些未关闭的getWriter(). 来源:http://blog.csdn.net/wonder4/article/ ...
- L1范数与L2范数
L1范数与L2范数 L1范数与L2范数在机器学习中,是常用的两个正则项,都可以防止过拟合的现象.L1范数的正则项优化参数具有稀疏特性,可用于特征选择:L2范数正则项优化的参数较小,具有较好的抗干 ...
- GIT导出差异版本更新的文件列表
之前写了一篇SVN导出差异版本更新的文件列表 这次写git如何导出差异化版本文件列表 查找了一番,发现git diff这个命令 $ git diff 2da595c daea1d6 --name-on ...
- win7 / mysql-8.0.11-winx64 安装的测坑步骤
虚惊一场,主要问题是 Navicat Premium 连接 mysql8 Client does not support authentication . 1. 下载 官网下载压缩包: mysql ...
- 【笔记】Rancher2.1容器云平台新特性
2018年10月6日,Rancher2.1版本正式发布.相比Rancher2.0版本,提供了许多新的特性: 1.支持集群和项目级别的硬件资源配额管理:2.支持3个节点的Rancher Server的管 ...
- Disable access to Windows Update
Disable access to Windows Update If this policy setting is enabled, all Windows Update features are ...
- SKU : Stock Keeping Unit
Stock Keeping Unit is a number assigned to a product by a retail store to identify the price, produ ...
- [Web Service] Java Web Services Tutorial
两种主要的java web services api: JAX-WS 和JAX-RS. Java web service application 之间通过WSDL来交互. 有两种方法来书写java w ...
- 如何 dump jvm 内存及线程栈
1. dump jvm 内存 命令格式: jmap -dump:format=b,file=dump_file_name pid举例:dump pid 为 3239 的 java 进程的内存到 aa. ...