【NOIP2013TG】solution

D1T1:转圈游戏(circle)

题意:看题目。。

解题思路:快速幂求m*10^kmodn即可。

#include<stdio.h>
#define ll long long
#define For(i,a,b) for(int i=a; i<=b; i++)
#define Ford(i,a,b) for(int i=a; i>=b; i--)
#define File(fn) freopen(fn".in","r",stdin);freopen(fn".out","w",stdout);
int n,m,k,x;
inline int in(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<‘0‘||ch>‘9‘) f=ch==‘-‘?-1:1,ch=getchar();
    while(ch>=‘0‘&&ch<=‘9‘) x=x*10+ch-‘0‘,ch=getchar();
    return x*f;
}
inline void print(int x,char ch){
    if (!x){
        putchar(‘0‘);
        putchar(ch);
        return;
    }
    if (x<0){
        putchar(‘-‘);
        x*=-1;
    }
    char num[10];
    short cnt=0;
    while(x) num[++cnt]=x%10+‘0‘,x/=10;
    while(cnt) putchar(num[cnt--]);
    putchar(ch);
}
inline ll ksm(int a,int k){
    if (!k) return 1;
    if (!(k^1)) return a;
    ll t=ksm(a,k>>1)%n;
    t*=t;t%=n;
    if (k&1) t*=a;
    t%=n;
    return t;
}
int main(){
    n=in(),m=in(),k=in(),x=in();
    print((ksm(10,k)*m%n+x)%n,‘\n‘);
}

D1T2:火柴排队

题意:将一个数组中元素进行几次交换后使得这个数组的大小顺序与另一个数组相同。

解题思路:离散后排序求逆序对数。

#include<stdio.h>
#include<algorithm>
#define ll long long
#define For(i,a,b) for(int i=a; i<=b; i++)
#define Ford(i,a,b) for(int i=a; i>=b; i--)
#define File(fn) freopen(fn".in","r",stdin);freopen(fn".out","w",stdout);
#define mod 99999997
using namespace std;
struct zxy{
    int num,no;
}a[100001],b[100001];
int n,ans=0,c[100001],BIT[100001];
inline int in(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<‘0‘||ch>‘9‘) f=ch==‘-‘?-1:1,ch=getchar();
    while(ch>=‘0‘&&ch<=‘9‘) x=x*10+ch-‘0‘,ch=getchar();
    return x*f;
}
inline void print(int x,char ch){
    if (!x){
        putchar(‘0‘);
        putchar(ch);
        return;
    }
    if (x<0){
        putchar(‘-‘);
        x*=-1;
    }
    char num[10];
    short cnt=0;
    while(x) num[++cnt]=x%10+‘0‘,x/=10;
    while(cnt) putchar(num[cnt--]);
    putchar(ch);
}
bool cmp(zxy a,zxy b){
    return a.num<b.num;
}
void init(){
    n=in();
    For(i,1,n) a[i].num=in(),a[i].no=i;
    For(i,1,n) b[i].num=in(),b[i].no=i;
    sort(a+1,a+n+1,cmp);
    sort(b+1,b+n+1,cmp);
    For(i,1,n) c[b[i].no]=a[i].no;
}
inline int lowbit(int k){
    return k&(-k);
}
inline void update(int x,int ad){
    while(x<=n){
        BIT[x]+=ad;
        x+=lowbit(x);
    }
}
inline int query(int x){
    int sum=0;
    while(x){
        sum+=BIT[x];
        x-=lowbit(x);
    }
    return sum;
}
void solve(){
    For(i,1,n){
        update(c[i],1);
        ans+=(i-query(c[i]));
        ans%=mod;
    }
    print(ans,‘\n‘);
}
int main(){
    init();
    solve();
    return 0;
}
时间: 2024-10-25 07:13:57

【NOIP2013TG】solution的相关文章

about家庭智能设备部分硬件模块功能共享【协同工作】solution

本人设备列表: Onda tablet {Android} wifi Desktop computer {win7.centos7} 外接蓝牙adapter PS interface 键盘.鼠标{与同局域网laptop通过synergy软件共享,使其成为共享的输入设备} 3.5mm interface低音炮{通过Bluetooth连接laptop,从而让laptop也可以使用该声音输出设备} 250G硬盘,通过在linuxcentos上搭建NFSNetwork File System,使其硬盘资

【NOIP2016TG】solution

传送门:https://www.luogu.org/problem/lists?name=&orderitem=pid&tag=83%7C33 D1T1(toys) 题意:有n个小人,给你M条指令,每条指令可顺可逆(时针),问你操作后的位置在哪. 解题思路:裸模拟即可. #include<stdio.h> using namespace std; #define MN 100005 char a[MN][15]; int n,m; bool b[MN]; inline int

【NOIP2011TG】solution

老师最近叫我把NOIPTG的题目给刷掉,于是就开始刷吧= = 链接:https://www.luogu.org/problem/lists?name=&orderitem=pid&tag=83%2C28 D1T1:carpet 题意简析:一个平面内有多个矩形按顺序覆盖平面,问覆盖后某个点属于哪个矩形. 解题思路:从n~1倒着check点有没有在矩形内即可,时间效率O(n). #include<cstdio> #include<iostream> #include&l

【leetcode】solution in java——Easy2

转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6410409.html 6:Reverse String Write a function that takes a string as input and returns the string reversed. 此题:字符串反转题. 思路:此题大一学C++的时候上机题就做过了,当时思路是:把String转化为char[],从尾到头遍历一次倒序地把字符复制到另一个数组(从头到尾),然后把新数组toStrin

【NOIP2014TG】solution

链接:https://www.luogu.org/problem/lists?name=&orderitem=pid&tag=83|31 D1T1(rps) 题意:给你一个周期,以及胜负关系,求A和B的胜场. 解题思路:暴力抄表,然后暴力计算即可. #include<cstdio> #include<iostream> using namespace std; int a[201],na,nb,b[201],ansa,ansb,n; int f[5][5]{{0,0

【LeetCode】Dungeon Game 解题报告【Solution】

[题目] The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight h

【LeetCode】【Solution】Maximum Product Subarray

[题目] Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest product = 6. [解法] 参考 http://segmentfault.com/blog

【LeetCode】Fraction to Recurring Decimal【Solution】

[题目] Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. For example, Given numerator = 1, denominator = 2,

【故障处理】告警日志报“ORA-01565 Unable To open Spfile”

[故障处理]告警日志报"ORA-01565 Unable To open Spfile" 1.1  BLOG文档结构图 1.2  故障分析及解决过程 1.2.1  故障环境介绍 项目 source db db 类型 RAC db version 12.1.0.2.0 db 存储 ASM OS版本及kernel版本 SuSE Linux Enterprise Server(SLES 11) 64位 1.2.2  故障发生现象及报错信息 客户的12.1.0.2的RAC库告警日志报ORA-0