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]的更多相关文章

随机推荐

  1. Guitar Por如何演奏刮弦

    每当我们听到吉他现场演出的时候,看到吉他手在激烈的刮弦时,都觉得很酷,非常有感染力.刮弦在我们弹吉他或编曲时,会经常用到,虽然时间很短,但会为你加分不少. 那么我们应该如何演奏刮弦呢,我们先用E5和弦 ...

  2. flutter Dynamic updates 热更新 版本更新

    比较新的解释 https://juejin.im/entry/5c85c959f265da2d881b5eb8 https://my.oschina.net/u/1464083/blog/297880 ...

  3. C# 利用反射动态给模型Model 赋值

    https://www.cnblogs.com/waitingfor/articles/2220669.html object ff = Activator.CreateInstance(tt, nu ...

  4. 论文笔记:Decoders Matter for Semantic Segmentation: Data-Dependent Decoding Enables Flexible Feature Aggregation

    Decoders Matter for Semantic Segmentation: Data-Dependent Decoding Enables Flexible Feature Aggregat ...

  5. DTS(待了解)

    DTS(待了解)  vs trasaction事务 脏数据 && 脏数据的清理 永远返回非空对象(忌:返回空值) 异常: invoker(trackTrace:debug.releas ...

  6. 剑指offer:链表中倒数第k个结点

    问题描述 输入一个链表,输出该链表中倒数第k个结点. 解题思路 两个指针都指向头结点,第一个指针先移动k-1个结点,之后两指针同时移动,当第一个指针到链表尾的时候,第二个指针刚好指向倒数第k个结点. ...

  7. Unity3d外包公司|UE4外包公司:谷歌首款Daydream VR设备上手

    这款售价仅为79美元(约合人民币525元)的产品内含“够用”的手柄和一台头戴设备,只要你有一台支持月日,10月5日,dream平台的手机(未来将成为安卓平台的标配),就能体验VR的乐趣. 即使该产品最 ...

  8. [原][杂谈]如果人类的末日:"天网"出现

    本文由南水之源在2019年3月21日发布,转载需声明原作者 本文仅为一次基于科技发展与科幻小说的幻想,如果天网真的出现,请不要参考这篇逻辑破败的推论. 参考: 天网(Skynet),是电影<终结 ...

  9. js的点滴

    一些好的博客 http://www.cnblogs.com/coding4/p/7809063.html canvas http://www.cnblogs.com/coding4/p/5593954 ...

  10. js-对象的重要概念

    抽象 抽象是通过特定的实例抽取共同特征以后形成概念的过程.它强调主要特征,忽略次要特征.一个对象是现实世界中一个实体的抽象. 对象三个特性 1.封装 把客观事物封装成抽象的类,隐藏属性和方法的实现细节 ...