C++
treble_
这个作者很懒,什么都没留下…
展开
-
数据结构之排序
#include<iostream>using namespace std;/*直接输出*/void output(int a[]){ for(int i=0;i<10;i++) { cout<<a[i]<<" "; } cout<<endl;}/*直接插入排序*/void I...原创 2020-02-15 21:49:06 · 113 阅读 · 0 评论 -
C++ string 字符串处理
string s1,s2;1、获取字符串长度int length=s1.length();int length=s1.size();2、字符串比较(i) 可以直接比较if(s1<s2) 按字典顺序排列,小于为-1,等于为0;大于为1;(ii)也可利用函数s1.compare(s2) 同按字典顺序排列,小于为-1,等于为0;大于为1;s1.comp...原创 2020-02-14 23:11:15 · 65 阅读 · 0 评论 -
hdu1203(简单01背包)
I NEED A OFFER! Problem Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了。要申请国外的任何大学,你都要交纳一定的申请费用,这可是很惊人的。Speakless没有多少钱,总共只攒了n万美元。他将在m个学校中选择若干的(当然要在他的经济承受范围内)。每个学校...原创 2018-08-21 16:38:26 · 127 阅读 · 0 评论 -
hdu1171、hdu2602(简单01背包)
hdu1171将总额的一半作为背包容量,状态方程s[j]=max(s[j],s[j-v[i]]+v[i]);#include<iostream>#include<algorithm>#include<string.h>using namespace std;int v[5000];int s[250000];int main(void){...原创 2018-08-11 22:56:48 · 95 阅读 · 0 评论 -
hdu2546(01背包问题)
饭卡 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可...原创 2018-08-10 17:36:15 · 148 阅读 · 0 评论 -
poj2000,poj2390,poj2509
poj2000#include<iostream>using namespace std;int main(void){ int n; while(cin>>n&&n!=0) { int num=0; int i,m; for(i=1;;i++) { ...原创 2018-03-17 16:51:36 · 178 阅读 · 0 评论 -
poj2017、poj2665
poj2017 #include<iostream>using namespace std;int main(void){ int n; while(cin>>n&&n!=-1) { int miles=0; int a[n],b[n]; cin>>a[0]&...原创 2018-03-09 14:48:53 · 162 阅读 · 0 评论 -
poj1519
一开始没考虑到大数,wa了,之后改成字符串输入,再一个个转为整型相加#include<iostream>using namespace std;int main(void){ string s; int sum; while(cin>>s&&((int)s[0]-48!=0)) { int m=0; ...原创 2018-03-08 21:13:02 · 213 阅读 · 0 评论 -
poj1008
#include#includeusing namespace std;int main(){ string cale1[] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab原创 2018-02-05 21:46:35 · 195 阅读 · 0 评论 -
poj1004
简单的一个水题不过我之前以为%.2f表示保留两位小数只是取两位而不是四舍五入取两位,现在发现是四舍五入。#include#includeusing namespace std;int main(void){ double a[12]; double sum=0.00; for(int i=0;i<12;i++) { cin>>a[i];原创 2018-01-20 16:09:34 · 156 阅读 · 0 评论 -
线性表的顺序表示和实现
#include#includeusing namespace std;#define Initsize 100#define Addsize 10struct list{ int *a;//存储空间基址 int length;//当前表长 int listsize;//当前分配的存储长度};int initlist(list &l);//初始化int insert_(li原创 2018-01-20 15:03:36 · 333 阅读 · 0 评论 -
poj1013
解题思路参照他人,大概为每一枚硬币有两个元素,一为是否为真币,一为被怀疑为假币的程度。初始全为假币,且怀疑程度为0。当两边相等时则可确定为真币,当不相等时轻的一边怀疑程度减一,重的这边怀疑程度加一,当最后未被确定为真币且怀疑程度最大的则为假币,再根据其怀疑程度的正负判断是轻了还是重了。#include<iostream>using namespace std;typedef...原创 2018-02-09 13:56:04 · 149 阅读 · 0 评论 -
poj1003
HangooverDescriptionHow far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpen...原创 2018-03-08 21:15:03 · 272 阅读 · 0 评论 -
poj1007
用二维数组存要输入DNA序列,依次计算其中的反转数个数已经并存入另一个数组中,再每次挑选个数最少的输出DNA序列。select函数为每次找最小值函数,关键在于如何在下一次找最小值时排除之前已经输出的,在此用了结构体,其中有两个数据,一个存反转数个数,一个为标志表示该数值是否已经使用过。#includeusing namespace std;struct number{ int原创 2018-01-24 15:25:31 · 141 阅读 · 0 评论 -
poj1005
#includeusing namespace std;int main(void){ int n; cin>>n; double x[n],y[n]; int a[n]; for(int i=0;i<n;i++) { cin>>x[i]>>y[i]; int z=(x[i]*x[i]+y[i]*y[i])*3.原创 2018-01-22 19:23:48 · 150 阅读 · 0 评论