随笔分类 - 简单题目
摘要:题目:http://codeforces.com/contest/237/problem/A那么简单的题目,还是忘了考虑n = 1时的情况了。。。View Code 1 typedef long long ll; 2 const int N = 100001; 3 char str[N][10]; 4 int main() 5 { 6 int n; 7 int i; 8 while(~scanf("%d",&n)) 9 {10 getchar();11 for(i = 0; i < n; i++)12 {13 ...
阅读全文
摘要:题目:http://codeforces.com/contest/235/problem/A当给的 n 是奇数时,则是 n * (n - 1) * (n - 2),当是偶数时,则要从 n 往前枚举三个数,求出他们的最小公倍数,感觉最多不会枚举超过10个吧View Code 1 ll gcd(ll a,ll b) 2 { 3 if(!b) return a; 4 else return gcd(b,a % b); 5 } 6 ll lcm(ll a,ll b) 7 { 8 //cout<<"((((\n"; 9 return a / gcd(a,b) * b;1.
阅读全文
摘要:题目:http://acm.timus.ru/problem.aspx?space=1&num=1306很想说这个题目很无语,最后还是在discuss http://acm.timus.ru/forum/thread.aspx?id=19974&upd=634679402957920104里看的这个人说的,才过的View Code 1 typedef unsigned int ll; 2 int main() 3 { 4 priority_queue<ll>pr; 5 ll a; 6 int n,i; 7 //freopen("data.txt"
阅读全文
摘要:记九月的第一个小水题题目:http://poj.org/problem?id=3665好像是以前做过的一个比赛题目,当时没有过,后来再写也没有过。刚才看到,就又重新读了一遍题目,竟然发现,自己以前读错题目了,而且那时候总是检查程序,根本就没重新去读过题,悲剧!题目给的算法规则里第二条说要把最高分的牛的分数平均分给 除他以外的其他牛(当然,如果不能平分,那么就把多余的分数从第一头牛开始每个 + 1的分完,当然还是不能给自己加),然就是把分数按给每头牛(包括自己)错了好几次,View Code 1 #include <stdio.h> 2 #include <stdlib.h&g
阅读全文
摘要:随便看到的一个题题目:http://poj.org/problem?id=1674给出 n 个数,问最小的交换次数可以让这 n 个数变成升序排列的这个一开始还以为dp呢,可是想了好长时间也不知道怎么dp,原来是找给的n个数里的环的问题,比如说样例 22 3 5 4 1 这里面有两个环 {2,3,5,1},{4},2应该在的位置是 3,3应该在的位置是 5,5应该在的位置是 1,然后1 就到 2 了,所以就是一个环,然后最小的交换次数就是 n - 环数View Code 1 const int N = 10010; 2 struct node 3 { 4 int x; 5 in...
阅读全文
摘要:题目:http://poj.org/problem?id=2121很很简单的题,权当用map 做着玩吧,就是给出英文的数,然后让你转换成数字,注意当是 百,千,百万的时候的处理,不为别的,就为了那个打表,打的眼晕,最后还是打错了,交了两次才发现,汗View Code 1 #include<iostream> 2 #include<sstream> 3 #include<cstdio> 4 #include<cstring> 5 #include<algorithm> 6 #include<string> 7 #includ
阅读全文
摘要:题目:http://poj.org/problem?id=2231题意:给出 n 头牛,给出 n 头牛的位置,求出每头牛到其他牛的距离的总和按给的牛的位置从小到大排序,假设 第 i 头牛的位置为 xi ,那么它前面的牛的个数假设是 N 个,并且我们可以求出它前面这些牛的 x (位置)值的和 记为 sum,那么它前面的这些牛到他的距离就是 N * xi - sum,同样处理它后面的那些牛的距离,对每头牛都这样处理后,把每头牛到其他牛的距离总和相加,就是答案代码写的有点乱View Code 1 #include<iostream> 2 #include<cstdio> 3
阅读全文
摘要:1.http://acm.hdu.edu.cn/showproblem.php?pid=1000最简单那种A + B,一般OJ上都会有这道题目,只要学过c语言,都应该会写的,就不说了。2.http://acm.hdu.edu.cn/showproblem.php?pid=1002 简单的高精度加法问题,注意前导零和进位处理就没什么问题了3.http://acm.hdu.edu.cn/showproblem.php?pid=1228字符串简单处理,用c++里面的函数,还是很方便的。感觉最有价值的一个题目,因为学会了用这个函数,以后从句子里提取单个单词就方便多了View Code 1 #incl.
阅读全文
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include<iostream> 5 using namespace std; 6 #define N 100000 7 int a[N]; 8 int main() 9 {10 int i;11 int n;12 while(cin>>n)13 {14 memset(a,0,sizeof(a));15 for(i=0;i<n;i++)16 cin>>a[i];17 ...
阅读全文
摘要:这道题目的意思就是给一个N 一个P 求一个K 使得他们满足这样的关系 K^N=P;我是直接用的数学函数pow来求的,可能是题目要求的不高,变量用double型的就直接过了 1 #include<iostream> 2 #include<math.h> 3 using namespace std; 4 int main() 5 { 6 double n,p; 7 while(cin>>n>>p) 8 { 9 double k;10 k=pow(p,1/n);11 cout<<k<<endl;12 }13 re...
阅读全文
摘要:贪心类题目 1 #include<stdio.h> 2 #include<iostream> 3 #include<string.h> 4 #include<algorithm> 5 #include<math.h> 6 #include<stdlib.h> 7 using namespace std; 8 #define N 10010 9 struct node10 {11 double x,y;12 }a[N];13 bool cmp(node a,node b)14 {15 return a.x<b.x;16
阅读全文
摘要:题目倒是没什么说的,就是刚开始没有读明白,毫不犹豫的就错了,很纳闷,看了看代码以为是第一次在0层的情况下不用停留,没想到题目的要求是无论在那一层,只要停就得加5秒。 1 #include<stdio.h> 2 #include<iostream> 3 #include<string.h> 4 using namespace std; 5 int main() 6 { 7 int n,i,j,sum; 8 while(cin>>n,n) 9 {10 sum=0;11 cin>>i;12 sum+=(i*6+5);13 ...
阅读全文

浙公网安备 33010602011771号