SGU 105】的更多相关文章

链接: http://vj.acmclub.cn/contest/view.action?cid=168#problem/E 时限:250MS     内存:4096KB     64位IO格式:%I64d & %I64u 提交 状态 练习 SGU 105 问题描述 There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Given first N elements of that sequence. You must determ…
SGU 105-DIV 3 Problem's Link Mean: 定义这样一种数列:1,12,123.. 给出一个n,求这个数列中能被3整除的数的个数. analyse: 这道题可以用分析的方法解决: 对于正整数k,k+1,k+2总有 k+(k+1)+(k+2) =k+k+1+k+2 =3k+3 =3(k+1) 3(k+1)可以被3整除,而且,一个数是否能被3整除表现为它的各位数字之和能否被三整除. 这就意味着对于一个数12345678910111213...k(连写),我们可以从后面开始,…
There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Given first N elements of that sequence. You must determine amount of numbers in it that are divisible by 3. Input Input contains N (1<=N<=231 - 1). Output Write answer to the output. Sampl…
There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Given first N elements of that sequence. You must determine amount of numbers in it that are divisible by 3. Input Input contains N (1<=N<=231 - 1). Output Write answer to the output. Sampl…
一个数能整除3当且仅当各位数之和能整除3. 有了这个规律就好办了, 但是呢,仔细一看, n太大了, 都到 2^31 了.所以简单的模拟肯定不行. 这种貌似像数论的题,一时找不到好办法,就打表! 打表出来是这个样子 1 0    2 1    3 2    4 2    5 3    6 4    7 4    8 5    9 6    10 6 很有规律啊,1,22,3,44…… 如果我们把每三个看成一个(不算1),那么就是每三个元素增加2     于是首先想到是不是 n/3*2 呢? 实验几…
分析:很容易知道序列1,2,3, 4,5, 6......与3的关系就是1,2, 0,1, 2,0,......如果是在一个数后面添加一个数就变成了这种序列1, 0, 0, 1, 0, 0, 1, 0, 0.... 代码如下: ======================================================================================= #include<stdio.h> #include<string.h> #inc…
观察一下序列,每3个数一组,第一个数余1,不能,加第二个数后整除(第二个数本身余2),第三数恰整除.一行代码的事.011011011.... #include<iostream> using namespace std; int main() { int n; while(cin>>n) { cout<<n/3*2+(n%3==2?1:0)<<endl; } return 0; }…
VJ小组:SGU---48h/题 每道做出的题目写成题解,将传送门更新在这里. SGU:101 - 200 SGU - 107 水题 解题报告 SGU - 105 找规律水题 解题报告 SGU - 104 动态规划+记录路径 解题报告 SGU - 103 最短路变形 解题报告 SGU - 102 欧拉函数 解题报告 SGU - 101 无向图多重边欧拉回路的求解 解题报告…
SGU 100 A+B :太神不会 SGU 101 Domino: 题目大意:有N张骨牌,两张骨牌有两面有0到6的数字,能相连当且仅当前后数字相同,问能否有将N张骨牌连接的方案?思路:裸的欧拉回路,注意自环,连通 //sgu101 #include<iostream> #include<cstdio> #include <math.h> #include<algorithm> #include<string.h> #include<queu…
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的花窗安排得最具美感.有F束花,每一束花都不一样,至少有F个按顺序排成一行的花瓶.花瓶从左到右,依次编号1-V.而花放置的位置是可以改变的,花依次编号1到F.花的序号有一个特征,即是序号决定了花束出现在花瓶里的顺序.例如,有两束花编号i和j,满足i<j,那么i所在的花瓶一定要在j所在花瓶的左边,即是i…
538. Emoticons 题目连接: http://acm.sgu.ru/problem.php?contest=0&problem=538 Description A berland national nanochat Bertalk should always stay up-to-date. That's why emoticons highlighting was decided to be introduced. As making emoticons to be highligh…
531. Bonnie and Clyde 题目连接: http://acm.sgu.ru/problem.php?contest=0&problem=531 Description Bonnie and Clyde are into robbing banks. This time their target is a town called Castle Rock. There are n banks located along Castle Rock's main street; each…
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traffic Lights 最短路 104 Little Shop of Flowers 动态规划 105 Div 3 找规律 106 The Equation 扩展欧几里德 107 987654321 Problem 找规律 108 Self-numbers II 枚举+筛法递推 109 Magic of Dav…
10-5. 在存储模型中使用自定义函数 问题 想在模型中使用自定义函数,而不是存储过程. 解决方案 假设我们数据库里有成员(members)和他们已经发送的信息(messages) 关系数据表,如Figure 10-4 所示: Figure 10-4. A simple database of members and their messages 可能有这种情况,我们不允许入门级的程序员在数据库中创建存储过程,然而,又想封装members和他们发送的messages条数最多的业务逻辑,这个时候我…
表现: /home/sphinx-1.1.0/sphinx.c: In function 'php_sphinx_client_read_property':/home/sphinx-1.1.0/sphinx.c:105:2: error: too few arguments to function 'std_hnd->read_property'/home/sphinx-1.1.0/sphinx.c: In function 'zim_SphinxClient_updateAttributes…
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kilobytes input: standardoutput: standard ICPC (International Cardboard Producing Company) is in the business of producing cardboard boxes. Recently the…
sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Description Dominoes – game played with small, rectangular blocks of wood or other material, each identified by a number of dots, or pips, on its face. The bl…
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则拿出礼物放回盒子,如果没有礼物则不操作.问M个人拿出礼物个数的期望.(N,M<=100000) #include <cstdio> using namespace std; double mpow(double a, int n) { double r=1; while(n) { if(n&…
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operations with int64 type, all Delphi solutions for the problem 455 (Sequence analysis) run much slower than the same code written in C++ or Java. We do not gua…
311. Ice-cream Tycoon Time limit per test: 0.5 second(s)Memory limit: 65536 kilobytes input: standardoutput: standard You've recently started an ice-cream business in a local school. During a day you have many suppliers delivering the ice-cream for y…
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且从当前光标删除到第一个出错的位置(留下的字符串要么为空,要么每个字符都是对的).问你,他正确的打完该字符串最少需要花费的时间的期望值是多少 字符串的长度小于等于3000 题意有点绕,具体可以看看原题是怎么描述的 做法分析 首先确定这是一个概率DP的问题. 定义状态 f[i] 表示正确的打完前 i 个…
高级四则运算器—结对项目反思(193 & 105) 本周我和一位韩国同学(71061105)一起结对编程完成了我们的结对项目——高级的小学四则运算题目生成器. PSP表格   PSP2.1 Personal Software Process Stages Time Planning 计划 · Estimate · 估计这个任务需要多少时间 1.5h Development 开发 · Analysis · 需求分析 (包括学习新技术) 3h · Design Spec · 生成设计文档 5h ·…
令一个点的属性值为:去除这个点以及与这个点相连的所有边后得到的连通分量的节点数的最大值. 则树的重心定义为:一个点,这个点的属性值在所有点中是最小的. SGU 134 即要找出所有的重心,并且找出重心的属性值. 考虑用树形DP. dp[u]表示割去u点,得到的连通分支的节点数的最大值. tot[u]记录以u为根的这棵子树的节点数总和(包括根). 则用一次dfs即可预处理出这两个数组.再枚举每个点,每个点的属性值其实为max(dp[u],n-tot[u]),因为有可能最大的连通分支在u的父亲及以上…
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=170 解题报告:输入两个由'+'和'-'组成的字符串,让你判断第二个串能不能由第一个串中的字符交换位置得到,不能的话输出-1,能的话输出最少的需要交换的次数. 一开始以为是DP,后来仔细一看发现,+号之间相对的位置是固定的,就是说如果可以,+号在调换位置的过程中是不会跟+号调换的,只跟-号调换,只有这样才能保证交换的次数是最少的. #include<cstdio> #includ…
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=179 解题报告:输入一个合法的括号串,求出这个括号串的字典序的下一个串.(认为'(' < ')') 我的做法主要是用了生成字典序的下一个序列的思想: 1.从序列的尾部开始往前找,找到第一个升序的位置例如 2 5 4 3 对于这个序列来说就是2 5这个位置 2.然后在后面这个降序的序列中找到一个比这个2稍大一点的数跟2进行交换得到3 5 4 2 3.然后把这个位置的后面的串转过来得到3…
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=180 解题报告:一个裸的求逆序对的题,离散化+线段树,也可以用离散化+树状数组.因为这题中的数列有重复的而且范围特别大,所以要进行离散化,离散化的方法是, 首先按照输入的数字排个序,然后把整个数列扫一遍,得出每个数字离散化的结果,然后再按照输入的顺序把顺序调整回来就OK 了.线段树部分就不说了. #include<cstdio> #include<cstring> #…
H - The equation Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Submit Status Practice SGU 106 Description There is an equation ax + by + c = 0. Given a,b,c,x1,x2,y1,y2 you must determine, how many integer roots of this eq…
题目传送门 /* 题意:n*n的矩阵,放置k个king,要求king互相不能攻击,即一个king的8个方向都没有另外的king,求方案个数 状态压缩DP:dp[i][num[j]][s] 代表在第i行,放置num[j]个king,其状态为s时的方案数 首先对state进行筛选,即一行king左右相邻没有另外的king,确定tot 接着对第一行进行处理,对2~n行DP递推,同样要满足各种条件限制,num个数和不超过k,s1,s2状态也要ok 最后累加放置k个king时的方案数 详细解释:http:…
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=107 /* 题意:n位数的平方的后面几位为987654321的个数 尼玛,我看描述这一句话都看了半天,其实只要先暴力程序测试一边就知道规律 详细解释:http://www.cnblogs.com/Rinyo/archive/2012/12/04/2802089.html */ #include <cstdio> #include <iostream> #include…
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126 /* 找规律,智商不够,看了题解 详细解释:http://blog.csdn.net/ahfywff/article/details/7432524 */ #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <iostrea…