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. 用Python绘制一个感兴趣是数学公式图

    下面是函数sin,cos函数的图像: 代码如下: import numpy as np import pylab as pl import matplotlib.font_manager as fm ...

  2. Mac在Finder中显示隐藏文件

    1.显示隐藏文件 打开终端,输入下面的命令: defaults write com.apple.finder AppleShowAllFiles -bool true KillAll Finder   ...

  3. Git操作手册(开发人员)

    一.git信息配置 1.1配置git账号信息 Window ->Preferences -> Team -> Git -> Configuration,在点击AddEntry… ...

  4. Flask Web框架

    Flask依赖两个外部库:Werkzeug和Jinja2.Werkzeug是一个WSGI(在Web应用和多种服务器之间的标准Python接口)工具集:Jinja2负责渲染模板.所以在安装Flask之前 ...

  5. elasticsearch_.net_client_nest2.x_到_5.x常用方法属性差异

    目录: Elasticsearch .net client NEST 5.x 使用总结 elasticsearch_.net_client_nest2.x_到_5.x常用方法属性差异 Elastics ...

  6. “妄”眼欲穿之CSS 居中问题

    妄:狂妄: 不会的东西只有怀着一颗狂妄的心,假装能把它看穿吧. 作为一个什么都不会的小白,为了学习,特别在拿来主义之后写一些对于某些css布局的总结,进一步加深对知识的记忆.知识是人类的共同财富,中华 ...

  7. Qt551.窗口滚动条

    1.代码的方式来创建 ScrollArea,然后使用 倒是 正常(有滚动条显示),但是此方式太麻烦 不如直接拖控件来的方便直观快捷. 但是,直接拖控件的方式 ScrollArea中无法显示出 滚动条, ...

  8. load data导txt文件进mysql中的数据

    1.实验内容: 利用SQL语句“load data ”将“.txt”文本文件中的数据导入到mysql中 2.实验过程: 首先我创了一个txt(也可以是其他的),设置其编码为utf-8,在windows ...

  9. Oracle表空间的创建与删除

    ORACLE中,表空间是数据管理的基本方法,所有用户的对象要存放在表空间中,也就是用户有空间的使用权,才能创建用户对象.否则是不充许创建对象,因为就是想创建对象,如表,索引等,也没有地方存放,Orac ...

  10. js用解构来定义变量并赋值

    解构数组 var [a,b]=[1,2]; a //1 b //2 ------------- var [a,b]=[1,2,3,4]; a //1 b //2 ---------------- va ...