noip2013/day1/1/转圈游戏
- 总时间限制:
- 10000ms
- 单个测试点时间限制:
- 1000ms
- 内存限制:
- 128000kB
- 描述
-
n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏。按照顺时针方向给 n 个位置编号,从 0 到 n-1。最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置,……,依此类 推。
游戏规则如下:每一轮第 0 号位置上的小伙伴顺时针走到第 m 号位置,第 1 号位置小伙伴走到第 m+1 号位置,……,依此类推,第n − m号位置上的小伙伴走到第 0 号位置,第n-m+1 号位置上的小伙伴走到第1 号位置,……,第 n-1 号位置上的小伙伴顺时针走到第m-1 号位置。
现在,一共进行了 10k 轮,请问 x 号小伙伴最后走到了第几号位置。
- 输入
- 输入文件名为 circle.in。
输入共 1 行,包含 4 个整数 n、m、k、x,每两个整数之间用一个空格隔开。 - 输出
- 输出文件名为 circle.out。
输出共 1 行,包含 1 个整数,表示 10^k 轮后 x 号小伙伴所在的位置编号。 - 样例输入
-
10 3 4 5
- 样例输出
-
5
- 提示
- 对于 30%的数据,0 < k < 7;
对于 80%的数据,0 < k < 10^7;
对于 100%的数据,1 < n< 1,000,000,0 - 来源
- noip2013/day1/第一题
- 数学题注意取mod
-
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = ;
int m;
struct node{
int v,next;
}edge[];int head[maxn],num;
void add_edge(int x ,int y)
{
edge[++num].v=y;edge[num].next=head[x];head[x]=num;
}
bool vis[maxn];int son[maxn];
int siz=0x7fffffff,ans;
void dfs(int x)
{
vis[x]=;
son[x]=;
int tmp=;
for(int i=head[x];i;i=edge[i].next)
{
int v=edge[i].v;
if(vis[v])continue;
dfs(v);
son[x]+=(son[v]+);
tmp=max(son[v]+,tmp);
}
tmp=max(tmp,m-son[x]-);
if(tmp<siz || tmp==siz && ans>x)
{
ans=x;
siz=tmp;
} }
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(vis,,sizeof vis);num=;siz=0x7fffffff;ans=;
memset(head,,sizeof(head));
scanf("%d",&m);
int a,b;
for(int i=;i<m;i++)
{
scanf("%d%d",&a,&b);
add_edge(a,b);add_edge(b,a);
}
dfs();
printf("%d %d\n",ans,siz);
}
return ;
}
noip2013/day1/1/转圈游戏的更多相关文章
- 题解 【NOIP2013】转圈游戏
[NOIP2013]转圈游戏 Description n个小伙伴(编号从0到n-1)围坐一圈玩游戏.按照顺时针方向给n个位置编号,从0到n-1.最初,第0号小伙伴在第0号位置,第1号小伙伴在第1号位置 ...
- luoguP1965 转圈游戏(NOIP2013)(快速幂)
luogu P1965 转圈游戏 题目 #include<iostream> #include<cstdlib> #include<cstdio> #include ...
- [快速幂][NOIP2012]转圈游戏
转圈游戏 题目描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置, ...
- NOIP2013 Day1
1.转圈游戏 https://www.luogu.org/problem/show?pid=1965 这道题失误极大,把freopen注释掉了,导致第一题暴0. 注意:在考试时一定要留下最后的时间检查 ...
- 3285 转圈游戏 2013年NOIP全国联赛提高组
3285 转圈游戏 2013年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description n 个小伙伴 ...
- codevs3285转圈游戏
传送门 3285 转圈游戏 2013年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Descript ...
- 洛谷 P1965 转圈游戏
洛谷 P1965 转圈游戏 传送门 思路 每一轮第 0 号位置上的小伙伴顺时针走到第 m 号位置,第 1 号位置小伙伴走到第 m+1 号位置,--,依此类推,第n − m号位置上的小伙伴走到第 0 号 ...
- 1617:转圈游戏 ybt
1617:转圈游戏 时间限制: 1000 ms 内存限制: 524288 KB提交数: 540 通过数: 326 [题目描述] nn 个小伙伴(编号从 00 到 n−1n−1 ...
- 洛谷P1965 转圈游戏 [2013NOIP提高组 D1T1][2017年6月计划 数论04]
P1965 转圈游戏 题目描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 ...
随机推荐
- SQL中的函数用法
一.coalesce COALESCE (expression_1, expression_2, ...,expression_n)依次参考各参数表达式,遇到非null值即停止并返回该值.如果所有的表 ...
- c++实验5
设计并实现一个机器宠物类MachinePets #include <iostream> #include <string> using namespace std; class ...
- error LNK2001: unresolved external symbol __imp___time64
Q: vs2005 generate a static lib(libva.lib), used in vc++6.0, error LNK2001: unresolved external symb ...
- luogu2023 [AHOI2009]维护序列
线段树加乘懒标记裸题. #include <iostream> #include <cstdio> using namespace std; typedef long long ...
- java并发之(4):Semaphore信号量、CounDownLatch计数锁存器和CyclicBarrier循环栅栏
简介 java.util.concurrent包是Java 5的一个重大改进,java.util.concurrent包提供了多种线程间同步和通信的机制,比如Executors, Queues, Ti ...
- SQL语句Not IN优化方案
总结网友们在CSDN社区上对于not in的优化策略,整理如下,备查. select * from emp where emp_no not in (select emp_no from emp ...
- error C2011: “Picture”:“struct”类型重定义
今天引用外来库时出现问题,也许是版本问题. 错误如下: .....\oursun\cincludes\quickdraw.h(309): error C2011: “Picture”:“struct” ...
- Monkey log分析说明
运行命令: adb shell monkey -p com.crazyhornets.MyHokageAndroidZSY -v -v -v 20 -- throttle 1000 Log: :Mon ...
- 正则表达式re模块的详解-python
1.元字符([ ]),它用来指定一个character class.所谓character classes就是你想要匹配的字符(character)的集合.字符(character)可以单个的列出,也 ...
- [oldboy-django][2深入django]django模板使用函数
1 模板引入子html--include 模板引擎 - 母版 - include,导入公共的html a. 用法:{% include "pub.html" %}, pub.htm ...