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. windows eclipse直接访问远程linux hadoop开发环境配置(符合实际开发的做法)

    CDH 5.x搭建请参考CentOS 7离线安装CDH 5.16.1完全指南(含各种错误处理). 如果使用的是cloudera quickstart vm,则只能在linux服务器中使用eclipse ...

  2. Linux 系统调用(system call)

    1 系统调用:(SYSTEM CALL) 操作系统(operating system)内核中有一组实现系统功能的过程,系统调用就是对上述过程的调用.程序员利用系统调用,向OS提出服务请求,由OS代为完 ...

  3. Python3 tkinter基础 Spinbox 可输入 能调整的 从指定范围内选择参数的控件

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. 实验9-1 编写一个存储过程proc_test_func

    在TestDB数据库中,编写一个存储过程proc_test_func,要求如下: 1)输入参数 一个整型的输入参数 @value 2)要求在一个select语句返回: @value的绝对值, 此绝对值 ...

  5. 用shell统计表格数据

    今天有个人问了这样一个问题,图片是原题,在这个题的基础上写了一个实现方法 首先日志存到a.txt文本里,如下 Zhangsan|lisi1|0|Zhangsan|lisi2|10|Zhangsan|l ...

  6. selenium+java二元素定位

    页面元素定位是自动化中最重要的事情, selenium Webdriver 提供了很多种元素定位的方法.  测试人员应该熟练掌握各种定位方法. 使用最简单,最稳定的定位方法. 自动化测试步骤 定位元素 ...

  7. Cordova入门系列(一)创建项目

    Cordova是什么? 初学Cordova的人,虽然了解一点点,知道Cordova是用来将html, css, js变成app的,但并不知道到底是怎么用的,原理是什么.经常会有这样的困惑: 它是一个可 ...

  8. mint修改host

    sudo xed /etc/hosts # Pycharm 0.0.0.0 account.jetbrains.com0.0.0.0 www.jetbrains.com #sublime text3 ...

  9. Hadoop分布式文件系统HDFS的工作原理

    Hadoop分布式文件系统(HDFS)是一种被设计成适合运行在通用硬件上的分布式文件系统.HDFS是一个高度容错性的系统,适合部署在廉价的机器上.它能提供高吞吐量的数据访问,非常适合大规模数据集上的应 ...

  10. 学习web components

    javascript里的两种组件 1 autonomous custom elements 一般extends HTMLElement, 可以通过<popup-info>或doducmen ...