`````` #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int t=0,i,v;
int n[7];
int dp[60001];

bool flag =false;
int imax(int a,int b)
{
return (a>b?a:b);
}

void comepletepack(int cost,int weight)
{
for(i=cost;i<=v;++i)
{
dp[i]=imax(dp[i],dp[i-cost]+weight);
if(dp[i]==v)
{
flag =true;
return;
}
}
}
void onezeropack(int cost,int weight)
{
for(i=v;i>=cost;--i)
{
dp[i]=imax(dp[i],dp[i-cost]+weight);
if(dp[i]==v)
{
flag =true;
return;
}
}
return;
}
void mutipack(int cost,int weight,int amount)
{
if(cost*amount>=v)
{
comepletepack(cost,weight);
return;
}
if(flag)
return;
int k=1;
while(k<amount)
{
onezeropack(k*cost,k*weight);
if(flag)
return;
amount-=k;
k*=2;
}
onezeropack(amount*cost,amount*weight);

}

int main()
{
int sum;
while(scanf("%d %d %d %d %d %d",&n[1],&n[2],&n[3],&n[4],&n[5],&n[6]))
{
++t;
sum =n[1]+2*n[2]+3*n[3]+4*n[4]+5*n[5]+6*n[6];
if(sum==0)
break;
if(sum%2!=0)
{
cout<<"Collection #"<<t<<':'<<endl;
cout<<"Can't be divided."<<endl;
cout<<endl;
continue;
}
v=sum/2;
memset(dp,-1,sizeof(dp));
dp[0]=0;
flag =false;
for(i=1;i<=6;++i)
{
mutipack(i,i,n[i]);
if(flag)
break;
}

if(!flag)
{
cout<<"Collection #"<<t<<':'<<endl;
cout<<"Can't be divided."<<endl;
cout<<endl;
}
else
{
cout<<"Collection #"<<t<<':'<<endl;
cout<<"Can be divided."<<endl;
cout<<endl;
}
}
return 0;
}
``````

`````` #include<iostream>
#include <cstring>
using namespace std;

int n[7];  //价值为i的物品的个数
int v;  //背包容量
int SumValue;  //物品总价值
bool flag;    //标记是否能平分SumValue
int dp[100000];  //状态数组

int max(int a,int b)
{
return a>b?a:b;
}

/*完全背包*/
void CompletePack(int cost,int weight)
{
for(int i=cost;i<=v;i++)
{
dp[i]=max(dp[i],dp[i-cost]+weight);
if(dp[i]==v)    //剪枝，当能够平分SumValue时退出
{
flag=true;
return;
}
}

return;
}

/*01背包*/
void ZeroOnePack(int cost,int weight)
{
for(int i=v;i>=cost;i--)
{
dp[i]=max(dp[i],dp[i-cost]+weight);
if(dp[i]==v)    //剪枝
{
flag=true;
return;
}
}
return;
}

/*多重背包*/
void MultiplePack(int cost,int weight,int amount)
{
if(cost*amount>=v)
{
CompletePack(cost,weight);
return;
}

if(flag)    //剪枝
return;

/*二进制优化*/
int k=1;
while(k<amount)
{
ZeroOnePack(k*cost,k*weight);

if(flag)    //剪枝
return;

amount-=k;
k*=2;
}
ZeroOnePack(amount*cost,amount*weight);

return;
}

int main(int i)
{
int test=1;
while(cin>>n[1]>>n[2]>>n[3]>>n[4]>>n[5]>>n[6])
{
SumValue=0;  //物品总价值

for(i=1;i<=6;i++)
SumValue+=i*n[i];

if(SumValue==0)
break;

if(SumValue%2)    //sum为奇数，无法平分
{
cout<<"Collection #"<<test++<<':'<<endl;
cout<<"Can't be divided."<<endl<<endl;    //注意有空行
continue;
}

v=SumValue/2;
memset(dp,-1,sizeof(dp));
dp[0]=0;
flag=false;

for(i=1;i<=6;i++)
{
MultiplePack(i,i,n[i]);

if(flag)    //剪枝
break;
}

if(flag)
{
cout<<"Collection #"<<test++<<':'<<endl;
cout<<"Can be divided."<<endl<<endl;
continue;
}
else
{
cout<<"Collection #"<<test++<<':'<<endl;
cout<<"Can't be divided."<<endl<<endl;
continue;
}
}
return 0;
}

``````

1个回答

poj3295 运行输入之后就崩溃了 求大神看看 英汉题意如下
Description WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some subset of the possible symbols K, A, N, C, E, p, q, r, s, t. A Well-formed formula (WFF) is any string of these symbols obeying the following rules: p, q, r, s, and t are WFFs if w is a WFF, Nw is a WFF if w and x are WFFs, Kwx, Awx, Cwx, and Ewx are WFFs. The meaning of a WFF is defined as follows: p, q, r, s, and t are logical variables that may take on the value 0 (false) or 1 (true). K, A, N, C, E mean and, or, not, implies, and equals as defined in the truth table below. Definitions of K, A, N, C, and E w x Kwx Awx Nw Cwx Ewx 1 1 1 1 0 1 1 1 0 0 1 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 1 1 A tautology is a WFF that has value 1 (true) regardless of the values of its variables. For example, ApNp is a tautology because it is true regardless of the value of p. On the other hand, ApNq is not, because it has the value 0 for p=0, q=1. You must determine whether or not a WFF is a tautology. Input Input consists of several test cases. Each test case is a single line containing a WFF with no more than 100 symbols. A line containing 0 follows the last case. Output For each test case, output a line containing tautology or not as appropriate. Sample Input ApNp ApNq 0 Sample Output tautology not 大概题意 输入由p、q、r、s、t、K、A、N、C、E共10个字母组成的逻辑表达式， 其中p、q、r、s、t的值为1（true）或0（false），即逻辑变量； K、A、N、C、E为逻辑运算符， K --> and: x && y A --> or: x || y N --> not : !x C --> implies : (!x)||y E --> equals : x==y 问这个逻辑表达式是否为永真式。 PS:输入格式保证是合法的 我的 代码 ``` #include <iostream> #include <vector> #include <string> #include <stack> using namespace std; bool c(bool a,bool b) { if(a&&!b) { return false; } else { return true; } } bool e(bool a,bool b) { if(a&&b||!a&&!b) { return true; } else { return false; } } bool solve(string str,int p,int q,int r,int s,int t) { stack <bool> ele; unsigned int i; for(i=str.size()-1;i>=0;i--) { switch(str[i]) { case 'p':ele.push((bool)p);break; case 'q':ele.push((bool)q);break; case 'r':ele.push((bool)r);break; case 's':ele.push((bool)s);break; case 't':ele.push((bool)t);break; case 'K': { bool a = ele.top(); ele.pop(); bool b = ele.top(); ele.pop(); ele.push(a&&b); } break; case 'A': { bool a = ele.top(); ele.pop(); bool b = ele.top(); ele.pop(); ele.push(a||b); } break; { case 'N': bool a = ele.top(); ele.pop(); ele.push(!a); } break; case 'C': { bool f = ele.top(); ele.pop(); bool g = ele.top(); ele.pop(); ele.push(c(f,g)); } break; case 'E': { bool h = ele.top(); ele.pop(); bool j = ele.top(); ele.pop(); ele.push(e(h,j)); break; } default:break; } } return ele.top(); } int main() { string str; bool flag = true; int i = 0; vector <string> ans; while(cin>>str&&str!="0") { int p,q,r,s,t; for(p=0;p<=1;p++) { for(q=0;q<=1;q++) { for(r=0;r<=1;r++) { for(s=0;s<=1;s++) { for(t=0;t<=0;t++) { flag = solve(str,p,q,r,s,t); if(!flag) break; } if(!flag) break; } if(!flag) break; } if(!flag) break; } if(!flag) break; } if(flag) { ans.push_back("tautology"); } else { ans.push_back("not"); flag = true; } } for(i=0;i!=ans.size();i++) { cout<<ans[i]<<endl; } return 0; } ```
poj 1276 背包问题 编译错误 求大神看看 英汉题意如下
Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say Dk, k=1,N, and for each denomination Dk the machine has a supply of nk bills. For example, N=3, n1=10, D1=100, n2=4, D2=50, n3=5, D3=10 means the machine has a supply of 10 bills of @100 each, 4 bills of @50 each, and 5 bills of @10 each. Call cash the requested amount of cash the machine should deliver and write a program that computes the maximum amount of cash less than or equal to cash that can be effectively delivered according to the available bill supply of the machine. Notes: @ is the symbol of the currency delivered by the machine. For instance, @ may stand for dollar, euro, pound etc. Input The program input is from standard input. Each data set in the input stands for a particular transaction and has the format: cash N n1 D1 n2 D2 ... nN DN where 0 <= cash <= 100000 is the amount of cash requested, 0 <=N <= 10 is the number of bill denominations and 0 <= nk <= 1000 is the number of available bills for the Dk denomination, 1 <= Dk <= 1000, k=1,N. White spaces can occur freely between the numbers in the input. The input data are correct. Output For each set of data the program prints the result to the standard output on a separate line as shown in the examples below. Sample Input 735 3 4 125 6 5 3 350 633 4 500 30 6 100 1 5 0 1 735 0 0 3 10 100 10 50 10 10 Sample Output 735 630 0 0 题意：有现今cash，和n种钱币，每种钱币有ni个，价值为di，求各种钱币组成的不超过cash的最大钱数....... ``` #include <iostream> #include <vector> #include <cstring> using namespace std; int imax(int a,int b) { return(a>b?a:b); } int main() { int cash; int nu; while(cin>>cash>>nu) { vector <int> l; l.push_back(0); int num=0; int n; int d; int i; int j; for(i=1;i<nu+1;++i) { cin>>n>>d; num+=n; for(j=0;j<n;++j) { l.push_back(d); } } int f[num+1][cash+1]; memset(f,0,sizeof(f)); i=0; j=0; for(int i=1;i<num+1;++i) { for(int j=cash;j>=l[i];--j) { f[i][j]=imax(f[i-1][j-l[i]]+l[i],f[i-1][j]); } } cout<<f[num][cash]<<endl; } return 0; } ```

#include<stdio.h> #include<stdlib.h> typedef struct tagDNA { char xulie[51]; int count; }DNA; int cmp(const void*a,const void*b) { return (*(DNA *)a).count>(*(DNA *)b).count?1:-1; } int main() { int n,m,i,j,k; DNA A[101],t; scanf("%d%d",&n,&m); for(i=0;i<m;i++) scanf("%s",A[i].xulie); for(i=0;i<m;i++) { for(j=0;j<n-1;j++) for(k=j+1;k<n;k++) if(A[i].xulie[j]>A[i].xulie[k]) A[i].count+=1; } qsort(A,m,sizeof(A[0]),cmp); for(i=0;i<m;i++)printf("%s %d\n",A[i].xulie,A[i].count); return 0; //n是字符串的长度，而m是测试的数据 } 我的测试结果和正确答案一样，为什么显示WA

ACM北大POJ_1376代码提交一直WA，求大神看看哪里错了？呜呜
---------- #include <iostream> #include <cstring> #include <queue> using namespace std; bool Map[55][55]; bool vis[55][55][4]; //[4] 四个directions，坐标和方向都相同时不能同时经过该点两次； int M,N; bool flag=false; //找到路径置为true； typedef struct { int x,y; //坐标； int time; //走到当前格子所用时间； int dir; //当前格子所朝方向； }point; point Start,End; bool canPass(int x,int y,int direction) { if(x<=0||x>=M||y<=0||y>=N) //走到边界； return false; if(vis[x][y][direction]|| !Map[x][y]|| !Map[x+1][y]|| !Map[x][y+1]||!Map[x+1][y+1]) return false; else return true; } void bfs() { point temp,temp1; queue <point> q; while(!q.empty()) //调用完后要清空队列； q.pop(); int dir1,dir2; q.push(Start); vis[Start.x][Start.y][Start.dir]=true; while(!q.empty()) { temp=q.front(); q.pop(); if((temp.x==End.x)&&(temp.y==End.y)) //到达终点； { flag=true; cout<<temp.time<<endl; return; } dir1=(temp.dir+1)%4; //0为south，1为east，2为north，3为west，每次转90度刚好dir+1或dir-1对4取余即可 dir2=(temp.dir-1+4)%4; temp1=temp; if(!vis[temp1.x][temp1.y][dir1]) //相同点不同方向没有访问过则入队； { vis[temp1.x][temp1.y][dir1]=true; temp1.dir=dir1; temp1.time++; q.push(temp1); } temp1=temp; if(!vis[temp1.x][temp1.y][dir2]) { vis[temp1.x][temp1.y][dir2]=true; temp1.dir=dir2; temp1.time++; q.push(temp1); } for(int i=0;i<3;i++) //走一步，两步，三步的情况全部进栈； { switch(temp.dir) { case 0: temp.x++; break; case 1: temp.y++; break; case 2: temp.x--; break; case 3: temp.y--; break; } if(!canPass(temp.x,temp.y,temp.dir)) break; else { vis[temp.x][temp.y][temp.dir]=true; if(i==0) temp.time++; //走1,2,3步都只需要耗时1秒,只需要第一次走一步时间加1就行； q.push(temp); } } } } int main() { int t; string s; while(cin>>M>>N&&(M||N)) { memset(Map,false,sizeof(Map)); memset(vis,false,sizeof(vis)); flag=false; for(int i=1;i<=M;i++) { for(int j=1;j<=N;j++) { cin>>t; Map[i][j]=t==0?true:false; //true(0)表示可以通行，false(1)表示不能走； } } cin>>Start.x>>Start.y>>End.x>>End.y; cin>>s; if(!canPass(Start.x,Start.y,Start.dir) ||!canPass(End.x,End.y,End.dir)) { cout<<"-1"<<endl; continue; //起始点和终点如果在边界或本身是障碍物则直接输出-1返回； } if(s=="south") Start.dir=0; else if(s=="east") Start.dir=1; else if(s=="north") Start.dir=2; else if(s=="west") Start.dir=3; bfs(); if(flag==false) cout<<"-1"<<endl; } return 0; }
poj1328求大神 题意如下
Input The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases. The input is terminated by a line containing pair of zeros Output For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case. Sample Input 3 2 1 2 -3 1 2 1 1 2 0 2 0 0 Sample Output Case 1: 2 Case 2: 1 题意：假设海岸线是一条无限延伸的直线。陆地在海岸线的一侧，而海洋在另一侧。每一个小的岛屿是海洋上的一个点。雷达坐落于海岸线上，只能覆盖d距离，所以如果小岛能够被覆盖到的话，它们之间的距离最多为d。 题目要求计算出能够覆盖给出的所有岛屿的最少雷达数目。 ``` #include <algorithm> #include <vector> #include <limits> #include <string> using namespace std; double d; int n; int t=0; bool flag = false; vector <int> ans; struct data { public: double start; double ends; }; bool compare(data a,data b) { return a.ends<b.ends; } int main() { while(cin>>n>>d&&(n!=0&&d!=0)) { vector <data> ils (n); int x,y,i; i=0; while(i!=n&&cin>>x>>y) { if(y>d) { flag = true; } data item; item.start = x - sqrt(d*d-y*y); item.ends = x + sqrt(d*d-y*y); ils[i] = item; ++i; } sort(ils.begin(),ils.end(),compare); i=0; int num = 0; double range; while(i<n) { range = ils[i].ends; while(++i<n) { if(ils[i].start>range) break; } ++num; } if(flag) { ans.push_back(-1); } else { ans.push_back(num); } n=d=i=num=0; ils.clear(); flag = false; } for(t=0;t!=ans.size();t++) { cout<<"case "<<t+1<<": "<<ans[t]<<endl; } return 0; } ```
Poj 1011 TLE...求大神指教0.0
enter code here #include<iostream> #include<algorithm> using namespace std; const int maxn = 65; int A[maxn]; bool used[maxn]; int n; bool cmp(int a,int b) { return a > b; } bool ok(int re,int len,int length) { if(re == 0 && len == length) return true; if(len == length) len = 0; for(int i = 0; i < n; i++) { if(used[i]) continue; if(A[i] > length - len) continue; used[i] = true; if(ok(re-1,len+A[i],length)) return true; used[i] = false; if(A[i] == len || len == length) break; } return false; } int main() { while(cin>>n) { if(n == 0) break; int tot = 0; for(int i = 0; i < n; i++) { used[i] = false; cin>>A[i]; tot += A[i]; } sort(A,A+n,cmp); for(int i = A[0]; i <= tot/2; i++) { if(tot%i == 0) { if(ok(n,0,i)) { cout<<i<<endl; break; } } } } return 0; } 求大神指出哪里TLE了0.0
poj1028 程序运行出错，哪位大神帮忙看一下
#include<iostream> #include<string> using namespace std; string f[101]={"0"}; string b[101]={"0"}; string curr; int main() { string cmd; curr="http://www.acm.org/"; while(cin>>cmd&&cmd!="QUIT") { if(cmd=="BACK") { if(b[0]=="0") cout<<"Ignored"<<endl; else { cout<<b[0]<<endl; for(int i=0;f[i]!="0";i++) f[i+1]=f[i]; f[0]=curr; curr=b[0]; for(int i=0;b[i]!="0";i++) b[i]=b[i+1]; } } if(cmd=="FORWARD") { if(f[0]=="0") cout<<"Ignored"<<endl; else { cout<<f[0]<<endl; for(int i=0;b[i]!="0";i++) b[i+1]=b[i]; b[0]=curr; curr=f[0]; for(int i=0;f[i]!="0";i++) f[i]=f[i+1]; } } if(cmd=="VISIT") { for(int i=0;b[i]!="0";i++) b[i+1]=b[i]; b[0]=curr; for(int i=0;f[i]!="0";i++) f[i]="0"; cin>>curr; cout<<curr<<endl; } } return 0; }
poj 2386这都题 这么做 哪里错了？ 求大神指点
``` #include<stdio.h> int n,m; char field[1000][1000]; int dx,dy,nx,ny,res; void dfs(int x,int y ) { field[x][y]='.'; for(dx=-1;dx<=1;dx++) { for(dy=-1;dy<=1;dy++) { nx=dx+x; ny=dy+y; if(0<=nx&&nx<n&&0<=ny&&ny<m&&field[nx][ny]=='W')dfs(nx,ny); } } } int main() { int i,j; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { getchar(); for(j=0;j<m;j++) { scanf("%c",&field[i][j]); } } res=0; for(i=0;i<n;i++) { for(j=0;j<m;j++) { if(field[i][j]=='W') { dfs(i,j); res++; } } } printf("%d\n",res); return 0; } ```
poj 2891 的源代码和站内线上解释
poj 2891 的源代码和站内线上解释，有解释才给分啊。。
poj 1363 线上指导+源代码
poj 1363 线上指导+源代码，最好有注释，并详细跟我解释~
POJ1166 求问错在哪里？

ACM一道题 poj3523 UVA1601双向广度优先BFS

POJ 2251 Dungeon Master（搜索）不知道为什么会超内存，求看看

poj 1226我的代码为什么wa，求hack，给出测试数据，或者思路的错误

poj 2058算法题Word Encoding完整代码

[1598 poj](http://poj.org/problem?id=1598 "") ``` #include <iostream> #include <fstream> #include <vector> #include <string> #include <algorithm> using namespace std; struct Excuse{ string s; int n; }; bool com(Excuse a,Excuse b){ return a.n > b.n; } int main(){ ifstream cin("aaa.txt"); vector<string> vk; vector<Excuse>vs; int n, m; string sk; string s,ss; int knum; Excuse e; int line = 1; while (cin >> n >> m){ vs.clear(); vk.clear(); //if (line != 1)cout << endl; for (int i= 0; i < n; i++){ cin >> sk; vk.push_back(sk); } getline(cin, ss); for (int j = 0; j < m; j++){ getline(cin, ss); s = ss; //大写字母变小写 for (int k = 0; k < s.size(); k++){ if (s[k] >= 'A'&&s[k] <= 'Z')s[k] = s[k] + 32; } knum = 0; //扫描关键子 for (int i = 0; i < vk.size(); i++){ int kn = vk[i].size(); for (int p = 0; p < s.size() - kn +1 ; p++){ //截取一个子串 string st = ""; for (int k = p; k < p + kn; k++){ st = st + s[k]; } //关键字在句首，且关键字后一字符不是字母； if (p == 0 && st == vk[i] && isalpha(s[p + kn])){ knum++; } //关键字在居中，且前后字符不是字母 else if (st == vk[i] && !isalpha(s[p + kn]) && !isalpha(s[p - 1]))knum++; } } e.s = ss; e.n = knum; vs.push_back(e); } sort(vs.begin(), vs.end(), com); cout << "Excute Set #" << line << endl; line++; for (int i = 0; i < vs.size(); i++){ if (i != 0 &&vs[i].n < vs[i - 1].n)break; //else if (i != 0 && vs[i].s == vs[i - 1].s)continue; cout << vs[i].s << endl; } cout << endl; } system("pause"); } ```

《奇巧淫技》系列-python！！每天早上八点自动发送天气预报邮件到QQ邮箱

8年经验面试官详解 Java 面试秘诀

MyBatis研习录(01)——MyBatis概述与入门
MyBatis 是一款优秀的持久层框架，它支持定制化 SQL、存储过程以及高级映射。MyBatis原本是apache的一个开源项目iBatis, 2010年该项目由apache software foundation 迁移到了google code并改名为MyBatis 。2013年11月MyBatis又迁移到Github。

Python爬虫爬取淘宝，京东商品信息

Java工作4年来应聘要16K最后没要,细节如下。。。

Python爬虫精简步骤1 获取数据

Python绘图，圣诞树，花，爱心 | Turtle篇

CPU对每个程序员来说，是个既熟悉又陌生的东西？ 如果你只知道CPU是中央处理器的话，那可能对你并没有什么用，那么作为程序员的我们，必须要搞懂的就是CPU这家伙是如何运行的，尤其要搞懂它里面的寄存器是怎么一回事，因为这将让你从底层明白程序的运行机制。 随我一起，来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说，我们首先就要搞明白它是怎么回事，也就是它的内部构造，当然，CPU那么牛的一个东...

web前端javascript+jquery知识点总结
1.Javascript 语法.用途 javascript 在前端网页中占有非常重要的地位，可以用于验证表单，制作特效等功能，它是一种描述语言，也是一种基于对象（Object）和事件驱动并具有安全性的脚本语言 ...
Python实战：抓肺炎疫情实时数据，画2019-nCoV疫情地图

Python：爬取疫情每日数据

B 站上有哪些很好的学习资源?

Web播放器解决了在手机浏览器和PC浏览器上播放音视频数据的问题，让视音频内容可以不依赖用户安装App，就能进行播放以及在社交平台进行传播。在视频业务大数据平台中，播放数据的统计分析非常重要，所以Web播放器在使用过程中，需要对其内部的数据进行收集并上报至服务端，此时，就需要对发生在其内部的一些播放行为进行事件监听。 那么Web播放器事件监听是怎么实现的呢？ 01 监听事件明细表 名...
3万字总结，Mysql优化之精髓

Python新型冠状病毒疫情数据自动爬取+统计+发送报告+数据屏幕（三）发送篇

1.Matlab实现粒子群算法的程序代码：https://www.cnblogs.com/kexinxin/p/9858664.html matlab代码求解函数最优值：https://blog.csdn.net/zyqblog/article/details/80829043 讲解通俗易懂，有数学实例的博文：https://blog.csdn.net/daaikuaichuan/article/...

1. 传统事件绑定和符合W3C标准的事件绑定有什么区别？ 传统事件绑定 &lt;div onclick=""&gt;123&lt;/div&gt; div1.onclick = function(){}; &lt;button onmouseover=""&gt;&lt;/button&gt; 注意： 如果给同一个元素绑定了两次或多次相同类型的事件，那么后面的绑定会覆盖前面的绑定 （不支持DOM事...