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 ...
随机推荐
- 1.编译azkaban
1.下载azkaban的源码 https://github.com/azkaban/azkaban.git 然后解压得到azkaban-master.zip,解压:unzip azkaban-mast ...
- HDU 3265/POJ 3832 Posters(扫描线+线段树)(2009 Asia Ningbo Regional)
Description Ted has a new house with a huge window. In this big summer, Ted decides to decorate the ...
- Python中除法:/和//
在Python中,除法有两种:/和//. X / Y 对于Python2.X来说,如果两个操作数都是整数,那么结果将向下取整(这个和C里面的不同,C里面是向0取整),也就是说,如果结果本来是-2.5, ...
- c++反射概念-简单介绍
C++ 反射机制的简单实现 C++并不支持反射机制,只能自己实现. 如果需要实现字字符串到函数到映射,一定要使用到函数指针. 简单实现反射机制,根据字符串来构造相应到类.主要有以下几点: (1) 可以 ...
- 2019寒假训练营第三次作业part2 - 实验题
热身题 服务器正在运转着,也不知道这个技术可不可用,万一服务器被弄崩了,那损失可不小. 所以, 决定在虚拟机上试验一下,不小心弄坏了也没关系.需要在的电脑上装上虚拟机和linux系统 安装虚拟机(可参 ...
- UVA725 Division (暴力求解法入门)
uva 725 Division Write a program that finds and displays all pairs of 5-digit numbers that between t ...
- 转 高性能IO模型浅析
高性能IO模型浅析 转自:http://www.cnblogs.com/fanzhidongyzby/p/4098546.html 服务器端编程经常需要构造高性能的IO模型,常见的IO模型有四种: ( ...
- 某一线互联网公司前端面试题总结css部分
1,css3选择器 :not(selector) 选择页面内所有type!=text的类型: input:not([type=text]){ color: red; font-weight: bold ...
- <T extends Comparable<? super T>>
在看Collections源代码中,看到如下代码: public static <T extends Comparable<? super T>> void sort(List ...
- 为什么 MongoDB (索引)使用B-树而 Mysql 使用 B+树
B-树由来 定义:B-树是一类树,包括B-树.B+树.B*树等,是一棵自平衡的搜索树,它类似普通的平衡二叉树,不同的一点是B-树允许每个节点有更多的子节点.B-树是专门为外部存储器设计的,如磁盘,它对 ...