【NOIP2013】day1
第一题:转圈游戏 http://codevs.cn/problem/3285/
本题的答案就是Ans = (x+m*10^k) mod n 这个没什么好说的,只是算法要用快速幂。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,k,x;
typedef long long ll;
ll mul(int x,int p)
{
ll tmp = x;
ll ret = 1;
while(p)
{
if(p&1)ret = (ret*tmp)%n;
tmp *= tmp;
ret %= n;
tmp %= n;
p>>=1;
}
return ret%n;
}
int main(void)
{
ios::sync_with_stdio(false);
cin>>n>>m>>k>>x;
cout<<(x+m*mul(10,k))%n;
return 0;
}
/*
Ans = (x+m*10^k) mod n
*/
第二题:火柴排队http://codevs.cn/problem/3286/
这道题很容易想到贪心,就是a数组中第一小对应b数组第一小。。类推