自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(48)
  • 收藏
  • 关注

原创 poj 3292 (前缀和)

就是素数筛选,但是乘积重复的只算一个;代码如下#include#include#include#includeusing namespace std;const int maxn=1000005;int prime[maxn];bool is_prime[maxn];int ans[maxn];void solve(){ int p=0; memset(is_pri

2017-08-31 10:21:10 269

原创 poj 2635

高精度求模+同余模定理 1、  Char格式读入K。把K转成千进制Kt,同时变为int型。把数字往大进制转换能够加快运算效率。若用十进制则耗费很多时间,会TLE。千进制的性质与十进制相似。例如,把K=1234567890转成千进制,就变成了:Kt=[  1][234][567][890]。为了方便处理,我的程序是按“局部有序,全局倒序”模式存放Kt

2017-08-31 08:55:28 170

原创 poj 1321

和八皇后问题差不多,但8皇后是n=k;而这一个n要多考虑一种情况;代码如下;#include#include#include#includeusing namespace std;char a[10][10];int total,m,n,k;int visit[10];void dfs(int cur){ if(m==k){ total++; retur

2017-08-29 20:00:58 230

原创 poj 2251

三维的bfs;代码如下#include#include#include#include#includeusing namespace std;struct node{ int x,y,z;}s,e,now,temp;int l,r,c;int visit[32][32][32];char a[32][32][32];int m[6][3]={{0,0,1},{0,

2017-08-29 14:22:20 222

原创 poj 3083

之前写了不少次,一直没过,过了几个月,就会写了。。当初是dfs不会写,现在dfs不会写,调试时bfs为0,把a[sx][sy]=='.'改成a[sx][sy]!='#'就行了难点是方向;如果从左边搜,是顺时针,反之是逆时针;花的比较丑,代码如下#include#include#include#include#includeusing namespace

2017-08-29 13:21:35 229

原创 poj 2406

也是循环节,代码如下#include#include#include#includeusing namespace std;int nextval[1000005];void Getnext(char s[],int len){ int j,k; j=0; k=nextval[0]=-1; while(j<len){ if(k==-1||s[j]==s[k]) nex

2017-08-29 12:12:29 192

原创 poj 1961

循环节是i-next[i];第一次超时是没直接用n,多用了strlen;代码如下#include#include#include#includeusing namespace std;int nextt[1000005];char s[1000005];int n;void Pre_next(char s[]){ int k,j; j=0; nextt[0]=k

2017-08-28 22:54:33 271

原创 poj 1942

这一次是怎么求阶乘的问题n,m已经到int的最大;杨辉三角是n^2/2;代码如下#include#include#include#includeusing namespace std;int main(){ long long n,m; double ans,t; while(~scanf("%I64d%I64d",&n,&m)){ if(n==0&&m=

2017-08-28 08:18:17 196

原创 poj 1019

代码如下#include#include#includeusing namespace std;unsigned int a[31270],s[31270];void reset()//打表{ int i; a[1]=1; s[1]=1; for(i=2;i<31270;i++) { a[i]=a[i-1]+(int)log1

2017-08-27 13:11:48 152

原创 poj 1850

一开始求组合出了问题26!大约是1e26,long long 都爆了。。后来才知道是用杨辉三角来求;组合数有两个公式;

2017-08-27 12:08:43 150

原创 poj 2586

最近状态有点差,总是不是这里写错一点,就是那里写错一点;亏损的放后面,可以保证公用代码如下;#include#include#include//2 3为5和7 #include//1 4 为3 和 9 using namespace std;int main(){int s,d;while(~scanf("%d%d",&s,&d)){int ans;

2017-08-26 19:27:01 188

原创 poj 2109

就这样吧,不是一个贪心题代码如下#include #include using namespace std; int main(void) { double n,p; while(cin>>n>>p) cout<<pow(p,1.0/n)<<endl; //指数的倒数就是开n次方 return 0;

2017-08-26 16:18:25 273

原创 poj 1836

求两遍LIS,枚举每个点代码如下#include#include#include#includeusing namespace std;int main(){ double h[1005],dp[1005]; int l[1005],r[1005]; int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf",&

2017-08-26 09:54:46 217

原创 poj 3267

还是没能自己独立做出来,dp还需要练代码如下#include#include#include#includeusing namespace std;int main(){ char a[605][27]; char b[305]; int w,l; scanf("%d%d",&w,&l); scanf("%s",&b); for(int i=0;i<w;i++)

2017-08-26 08:18:57 191

原创 poj 1276

多重背包,转化成01背包,可以用二进制优化复杂度为O(V*∑log n[i]);#include#include#includeusing namespace std;int dp[110000],t[30000],s[2000][2];int main(){ int cash,n; while(scanf("%d%d",&cash,&n)>0) {

2017-08-25 20:51:43 150

原创 poj 1837

状态从-7500到7500 转到0-15000;状态转移方程为dp[i][j+w[i]*c[i]]=dp[i-1][j];代码如下:#include#include#include#includeusing namespace std;int main(){ int n,g; int c[21],w[21]; int dp[25][15005]; scanf("%d

2017-08-25 19:21:52 106

原创 poj 1035

一开始没审题,直接用map,wa后来看见字典序,没理解意思,又wa后来才理解是输入的字典序。。上去一发,tle后来发现忘了break;代码如下#include#include#include#includeusing namespace std;int main(){ char a[10005][16]; char temp[16]; int num=0,

2017-08-25 14:04:10 165

原创 poj 1094

真的惨,弄了一下午。。晚上终于过了要先判断有序和有环的状态一直纠结的点终于搞明白了我一直纠结有很多点但一开始有一条边怎么处理,看了别人写的,这样是能跑满的,但不确定无序的情况我想明白了,如果一次入的顶点大于2,肯定就是无序的;如果长度小于n,就有环;代码如下#include#include#include#include#include#includeu

2017-08-24 19:54:43 154

原创 poj 3026

先bfs 再prim看的kuangbin巨巨的解题报告首先move会和c++的move发生冲突 ,编译器显示为ambigious;其次学会用pairvector >p;要用空格make_pair pair.first pair.second 代码如下#include#include#include#include#includeusing namespac

2017-08-22 21:07:34 168

原创 poj 1258

水题改了改poj 2458,直接交了#include #include #include #include using namespace std; const int INF=0x3f3f3f; bool used[505]; int mincost[505]; int cost[505][505]; int prim(int n) {

2017-08-22 16:20:32 137

原创 poj 2485

水题求最小生成树的最大边改一下条件就行prim#include#include#include#includeusing namespace std;const int INF=0x3f3f3f;bool used[505];int mincost[505];int cost[505][505];int prim(int n){ for(int i=1;i<=

2017-08-22 15:54:41 137

原创 poj 1789

prim就行不同字母为距离注意几个地方第一能不用string就不用string,就因为他超时了;第二cost[i][j]最好是i i+1不要是1 1这样for循环前者跑了438后者跑了579ms#include#include#include#include#includeusing namespace std;const int INF=1

2017-08-22 15:10:01 160

原创 poj 2240

代码如下#include#include#include#include#includeusing namespace std;const int INF=1e9+7;map p;double cost[35][35];int main(){ int n,cnt=0; while(~scanf("%d",&n)){ if(n==0) break; else {

2017-08-22 13:35:50 217

原创 poj 1125

用floyd求,代码如下#include#include#include#includeusing namespace std;const int INF=1e9+7;int cost[105][105];int main(){ int n; while(~scanf("%d",&n)){ if(n==0) break; for(int i=1;i<=n;i++)

2017-08-22 12:19:40 185

原创 poj 2253(dijkstra暂时不明白)

有两种写法但是我还是有点不太理解为什么要用最短路。。。。。。一种是floyd 我能理解,但是dijkstra我有点晕,后面的我明白,但是我不懂为什么每次还要再取最小的边;#include#include#include#include#includeusing namespace std;const int INF=1e9+7;double cost[205][205];

2017-08-22 08:36:41 185

原创 poj 1065

第三道最短路的题第一次写dijkstra;这个题一开始一直没读懂题意;后来明白了,因为但是如果他和某个地位较低的人进行了交易,地位较高的的人不会再和他交易,他们认为这样等于是间接接触,反过来也一样。因此你需要在考虑所有的情况以后给他提供一个最好的方案。 这意味着只能交易一次剩下的就是枚举加dijkstra;推荐两个题解我是结合着两个,按照我的理解写的点击打开链接

2017-08-21 20:28:36 229

原创 UVALive 7720

错了很久是因为要去求逆元同余模定理不适合除法举个例子30/2Mod4=(15)Mod4=3;要分开模就是1必须要用费马小定理来求在模为素数p的情况下,有费马小定理 a^(p-1)=1(mod p) 那么a^(p-2)=a^-1(mod p) 也就是说a的逆元为a^(p-2)剩下的就是快速幂取模long long pow4(int a,int

2017-08-20 18:49:11 284

原创 hdu 6154

就是一个找规律的题斜着的正方形面积最大因此8为8       18为12       依次类推从面积小的正方形到面积大的正方形转化分为4部画的比较丑代码如下#include#include#include#includeusing namespace std;int main(){ int t; scanf("%d",&t);

2017-08-20 08:07:03 338

原创 UVALive 7483

就是贪心;可以看自己写的贪心总结区间3大问题代码如下#include#include#include#includeusing namespace std;struct Node{ int l,u;}a[105];bool cmp(Node a,Node b){ if(a.u==b.u) return a.l>b.l; return a.u<b.u;}

2017-08-19 22:22:57 223

原创 区间问题 贪心总结

今天无意间在紫书上发现了这个问题分为3大类其中有一类正好是前几天wa的题第一类是选择不相交区间问题,即选择尽可能多的区间,使区间两两没有交点(a,b)如果一个区间被另一个区间完全包含,那一定去选小的区间、按照b从小到大排序分两种情况a2a2>a1 如果完全不相交,就没有影响否则只能二选一不选区间2,实际的有效部分被区间2包含,所以就不能选综上选择

2017-08-19 10:43:44 582

原创 poj 3259

题意是问你从某个点出发,回来的时间却是你出发之前的时间因为有虫洞,所以有负边用Bellman_Ford判断负环但是我发现没起点;看了别人的,就不用初始化为0了,剩下的都是一样的;这说明我对最短路的理解还是不透彻;第二个最短路的题目代码如下#include#include#include#includeusing namespace std;struct e

2017-08-19 09:18:24 127

原创 poj 1860

这是第一次做最短路的题n就是钱的种类,就是点m*2就是边要想有提高,就是有正环但要先交税,有可能有负边于是就用Bellman-Ford看了kuanbin巨巨写的,对怎么判断负环有了深刻的理解代码如下#include#include#include#includeusing namespace std;const int maxn=105;double d

2017-08-19 08:07:48 216

原创 flag

尽管我现在还是很菜区域赛也不知道会怎么样但是我相信一年后我能拿银甚至金牌一年的迷茫已经过去了现在就开始刷题poj和挑战程序设计竞赛一年内我要刷完----------------------------大大的flag

2017-08-18 08:56:47 189

原创 poj 2492

思路差不多,但要去判断同性恋自己手写在Union()写错了注意格式r[fx]=(r[x]+1+r[y])%2; //fx与x关系 + x与y的关系 + y与fy的关系 = fx与fy的关系这种叫种类并查集;#include#include#include#includeusing namespace std;const int maxn=2005;int p[max

2017-08-18 08:54:39 211

原创 poj 1703

并查集的高级使用加了一个r【】来判断与根节点的关系find()如果 a 和 b 的关系是 r1, b 和 c 的关系是 r2, 那么 a 和 c 的关系就是 (r1+r2)%2 Union()联合时,使得 p[fx] = fy; 同时也要寻找 fx 与 fy 的关系。关系为:(r[x]+r[y]+1)%2代码如下#include#include#incl

2017-08-18 08:19:01 244

原创 poj 3007

一开始用set存字符串超时了后来用hash判重 用set存懒得写函数了应该有8重hash=hash*key+xx;#include#include#include#include#includeusing namespace std;int main(){ int t; scanf("%d",&t); while(t--){ string s; ci

2017-08-17 20:50:06 233

原创 POJ 3096

map代码如下bool类型是默认为false#include#include#include#include#include using namespace std;int main(){ string s; while(cin>>s){ if(s[0]=='*'&&s.size()==1) break; if(s.size()==1||s.size()==2

2017-08-17 15:09:54 219

原创 hdu 5968

这个题不同的处理方式时间差距非常大第一次我超时了后来二分做的跑了700多ms#include#include#include#include#includeusing namespace std;int main(){ int t; scanf("%d",&t); while(t--){ int n,m; int a[105],b[105]; vec

2017-08-15 09:23:41 217

原创 hdu 5933

注意细节从左向右,贪心#include#include#include#includeusing namespace std;int main(){ int t,cnt=0; scanf("%d",&t); while(t--){ int n,k; scanf("%d%d",&n,&k); int a[100005]; long long sum=0;

2017-08-14 20:54:28 198

原创 HDU - 5935

注意精度速度不一定是整数#include#include#include#includeusing namespace std;#define eps (1e-8)int main(){ int t,cnt=0; scanf("%d",&t); while(t--){ int n; int a[100005]; scanf("%d",&n); a[0]=

2017-08-14 20:11:27 234

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除