Small Multiple
题目描述
Constraints
2≤K≤105
K is an integer.
输入
K
输出
样例输入
6
样例输出
3
提示
12=6×2 yields the smallest sum.

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int N=3e5+;
const int p=1e9+;
int k,cnt;
int dis[N],last[N];
bool vis[N];
struct orz{
int v,nex,s;}e[N*];
queue<int>q;
void add(int x,int y,int z)
{
cnt++;
e[cnt].v=y;
e[cnt].nex=last[x];
last[x]=cnt;
e[cnt].s=z;
}
void spfa()
{
for (int i=;i<k;i++) dis[i]=inf;
dis[]=; vis[]=;
q.push();
while (!q.empty())
{
int now=q.front(); q.pop();
for (int i=last[now];i;i=e[i].nex)
{
if (dis[e[i].v]>dis[now]+e[i].s)
{
dis[e[i].v]=dis[now]+e[i].s;
if (!vis[e[i].v])
{
vis[e[i].v]=;
q.push(e[i].v);
}
}
}
vis[now]=;
}
}
int main()
{
scanf("%d",&k);
for (int i=;i<k;i++)
{
add(i,(i+)%k,);
add(i,i*%k,);
} spfa(); printf("%d\n",dis[]+);
return ;
}
Small Multiple的更多相关文章
- Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ...
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ... 这个错误是因为有两个相 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- [LeetCode] Read N Characters Given Read4 II - Call multiple times 用Read4来读取N个字符之二 - 多次调用
The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...
- SharePoint "System.Data.SqlClient.SqlException (0x80131904): Parameter '@someColumn' was supplied multiple times.“
最近在处理SharePoint Office365的相关开发的时候发现了这样一个奇怪的现象: 无法通过API更新Editor field,只要已更新就会throw Exception,由于是Offic ...
- 2012Chhengdu K - Yet Another Multiple Problem
K - Yet Another Multiple Problem Time Limit:20000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher
加密代码 /**解密 * @param content 待解密内容 * @param password 解密密钥 * @return */ public static byte[] decrypt(b ...
- scala - multiple overloaded alternatives of method bar define default arguments
同名同位置默认参数不能overload def bar(i:Int,s:String="a"){} def bar(i:String,s:String="b") ...
- 基于Picture Library创建的图片文档库中的上传多个文件功能(upload multiple files)报错怎么解决?
复现过程 首先,我创建了一个基于Picture Library的图片文档库,名字是 Pic Lib 创建完毕后,我点击它的Upload 下拉菜单,点击Upload Picture按钮 在弹出的对话框中 ...
- 多文档上传(upload multiple documents)功能不能使用怎么办?
问题描述: 在SharePoint 2010的文档库里选择documents标签,然后选择upload document下拉菜单,你会发现upload multiple documents那个按钮是灰 ...
- OPEN CASCADE Multiple Variable Function
OPEN CASCADE Multiple Variable Function eryar@163.com Abstract. Multiple variable function with grad ...
随机推荐
- Python3 小工具-TCP发现
from scapy.all import * import optparse import threading import os def scan(ip): pkt=IP(dst=ip)/TCP( ...
- Linux系统inotify工具安装配置
inotify主要功能 Inotify 是一个 Linux特性,它监控文件系统操作,比如读取.写入和创建.Inotify 反应灵敏,用法非常简单,并且比 cron 任务的繁忙轮询高效得多.学习如何将 ...
- Reversing Encryption(模拟水题)
A string ss of length nn can be encrypted(加密) by the following algorithm: iterate(迭代) over all divis ...
- Python3.5在Windows7环境下Scrapy库的安装
Python3.5在Windows7环境下Scrapy库的安装 忙活了一下午,总算是把Scrapy库给装完了,记下来给需要帮助的人 首先安装的环境:Windows7 64位 Python的版本是:3. ...
- Java中 Auto-boxing/unboxing
Java 中 Auto-boxing/unboxing 机制,在合适的时机自动打包,解包. 1. 自动将基础类型转换为对象: 2. 自动将对象转换为基础类型: Demo_1: import java. ...
- redis——持久化方式RDB与AOF分析
https://blog.csdn.net/u014229282/article/details/81121214 redis两种持久化的方式 RDB持久化可以在指定的时间间隔内生成数据集的时间点快照 ...
- AutoResetEvent的基本用法
The following example uses an AutoResetEvent to synchronize the activities of two threads.The first ...
- MySQL错误解决10038
[错误解决]本地计算机上的mysql服务启动停止后,某些服务在未由其他服务或程序使用时将自动停止 标签: mysql计算机 2016-12-01 17:49 5508人阅读 评论(2) 收藏 举报 ...
- 第72天:jQuery实现下拉菜单
jQuery实现下拉菜单 一.居中 1.块元素居中:给块元素本身设置:margin:0 auto;,块元素必须设置宽度 2.行内块元素居中:给元素父级设置text-algin:center; < ...
- IOI 98 (POJ 1179)Polygon(区间DP)
很容易想到枚举第一步切掉的边,然后再计算能够产生的最大值. 联想到区间DP,令dp[i][l][r]为第一步切掉第i条边后从第i个顶点起区间[l,r]能够生成的最大值是多少. 但是状态不好转移,因为操 ...