#include<stdio.h>
int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
void knapsack(int m,int n,int w[],int p[])
{
int v[10][10],x[10],i,j;
for(i=0;i<=n;i++)
{
for(j=0;j<=m;j++)
{
if(j==0||i==0)
v[i][j]=0;
if(j-w[i]<0)
v[i][j]=v[i-1][j];
else
v[i][j]=max(v[i-1][j],v[i-1][j-w[i]]+p[i]);
}
}
for(i=0;i<=n;i++)
{
for(j=0;j<=m;j++)
printf("%d\t",v[i][j]);
printf("\n");
}
printf("THE OPTIMAL SOLUTION IS:%d",v[n][m]);
for(i=1;i<=n;i++)
x[i]=0;
i=n;
j=m;
while(i>0 && j>0)
{
if(v[i][j]!=v[i-1][j])
{
x[i]=1;
j=j-w[i];
}
i--;
}
printf("THE OPTIMAL SET OF WEIGHTS IS:");
for(i=1;i<=n;i++)
if(x[i]==1)
printf("%d\t",i);
printf("\n");
}
int main()
{
int w[10],p[10],i,m,n;
printf("ENTER THE NUMBER OF ITEMS:"); …Run Code Online (Sandbox Code Playgroud) 我有一个带有单个 TextView 的简单应用程序,它显示来自 ACTION_SEND 意图的纯文本。我的问题是,每次将某些文本共享给此应用程序时,都会创建一个新实例。在检查最近的应用程序时,我可以看到该应用程序的多个实例。我正在 API 23 上测试它。
这是我的代码:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("MainActivity.java", "onCreate");
((TextView) findViewById(R.id.temp_textview)).setText("Share text/links from other apps");
}
@Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
String action = intent.getAction();
intent.getFlags();
Log.d("onResume - intent: ",intent.toString());
String type = intent.getType();
TextView displayText = (TextView) findViewById(R.id.temp_textview);
if (Intent.ACTION_SEND.equals(action) && type!=null) {
Log.d("MainActivity.java", "Intent verified");
if ("text/plain".equals(type)) {
handleSendText(intent, displayText);
}
}
}
void handleSendText(Intent intent, TextView …Run Code Online (Sandbox Code Playgroud) 我已经做了几个月的轻微OpenGL编程,现在我想使用xscreensaver库编写一个屏幕保护程序.
我在问这个之前看过如何开发linux屏幕保护程序,但我认为这个问题不够具体.
我已经做了什么 -
我下载了xscreensaver源代码并阅读了README.hacking.我在源的hacks目录中使用greynetic.c(其中一个屏幕保护程序jwz建议用于理解自述文件中的xscreensaver)的代码.
我阅读了这个网页 - http://www.dis.uniroma1.it/~liberato/screensaver/simplesquares.html(来自链接问题的答案之一).我下载了simplesquares.c代码,我正在尝试运行它.
我的问题是什么 -
注意:您必须在gcc命令中添加-lX11,以便在编译simplesquares.c时链接X11库.否则它将返回未定义的引用错误.
编辑:
在编译屏幕保护程序greynetic.c时,它返回一些错误,其中一些我在这里重现:
greynetic.c:(.text+0x4f): undefined reference to `XGetWindowAttributes'
greynetic.c:(.text+0xa6): undefined reference to `get_boolean_resource'
greynetic.c:(.text+0xd9): undefined reference to `get_pixel_resource'
greynetic.c:(.text+0x112): undefined reference to `get_pixel_resource'
greynetic.c:(.text+0x13e): undefined reference to `get_integer_resource'
greynetic.c:(.text+0x185): undefined reference to `XCreateGC'
greynetic.c:(.text+0x1dd): undefined reference to `XCreatePixmapFromBitmapData'
Run Code Online (Sandbox Code Playgroud)
这可能是一个链接错误.
对于火力地堡文档的云功能在这里指出,这可以通过使用云计算功能来完成-
预渲染单页应用程序以改善SEO.这允许您创建动态元标记,以便在各种社交网络中共享.
我有两个问题:
有人可以用一个例子解释如何实现预渲染吗?
这与Firebase Hosting一起使用的方法如何?所以,假设我xyz.com/salon/43在Firebase托管中有一个网页,我有一个salon.html,响应此请求.现在为了能够预渲染我应该从托管移动到呈现网页的云功能吗?换句话说,我是从哪里来的
"rewrites": [{
"source": "/salon/*",
"destination": "/salon.html"}]
Run Code Online (Sandbox Code Playgroud)
至
"rewrites": [{
"source": "/salon", "function": "salon"}]
Run Code Online (Sandbox Code Playgroud)我正在研究Kruskal用于查找给定图形的MST的算法,并且我理解您必须首先将所有顶点视为森林的基本概念.之后,您必须找到最小边并将边的顶点连接到一个树中.并递归执行此操作,直到只剩下一个包含所有顶点的树.
我偶然发现了这个算法的以下实现.
#include<iostream.h>
int p[10];
void kruskal(int w[10][10],int n)
{
int min,sum=0,ne=0,i,j,u,v,a,b;
for(i=1;i<=n;i++)
p[i]=0;
while(ne<n-1)
{
min=999;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(w[i][j]<min)
{
min=w[i][j];
u=a=i;
v=b=j;
}
}
while(p[u])
u=p[u];
while(p[v])
v=p[v];
if(u!=v)
{
ne++;
sum+=min;
cout<<"\nedge "<<a<<"-->"<<b<<" is "<<min;
p[v]=u;
}
w[a][b]=w[b][a]=999;
}
cout<<"\nmin cost spanning tree= "<<sum;
}
void main()
{
int w[10][10],n,i,j;
clrscr();
cout<<"enter no.of vertices\n";
cin>>n;
cout<<"enter weight matrix\n";
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
cin>>w[i][j];
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(w[i][j]==0)
w[i][j]=999;
kruskal(w,n);
}
Run Code Online (Sandbox Code Playgroud)
我不明白的是需要:
while(p[u])
u=p[u];
while(p[v])
v=p[v];
Run Code Online (Sandbox Code Playgroud)
这两个while循环究竟做了什么?
编辑:以及 - 的必要性 …
我今天正在玩BeautifulSoup和Requests API.所以我想我会写一个简单的刮刀,它会跟随深度为2的链接(如果这是有道理的).我正在抓取的网页中的所有链接都是相对的.(例如:)<a href="/free-man-aman-sethi/books/9788184001341.htm" title="A Free Man">所以为了使它们绝对我认为我会加入页面url与相关链接使用urljoin.
要做到这一点,我必须首先从<a>标签中提取href值,为此我认为我会使用split:
#!/bin/python
#crawl.py
import requests
from bs4 import BeautifulSoup
from urlparse import urljoin
html_source=requests.get("http://www.flipkart.com/books")
soup=BeautifulSoup(html_source.content)
links=soup.find_all("a")
temp=links[0].split('"')
Run Code Online (Sandbox Code Playgroud)
这会出现以下错误:
Traceback (most recent call last):
File "test.py", line 10, in <module>
temp=links[0].split('"')
TypeError: 'NoneType' object is not callable
Run Code Online (Sandbox Code Playgroud)
在正确浏览文档之前潜入水中,我意识到这可能不是实现我的目标的最佳方法,但为什么会出现TypeError?
所以,让我们说在Firebase的公共文件夹中,我有一个index.html和一个salon.html.
现在对于xyz.com/salon/43我想要加载的URL salon.html和在javascript中我想从实时数据库中获取沙龙43.
现在我能够拥有像你这样的网址xyz.com/salon?id=43.我想知道是否有可能在Firebase托管中做前者,如果是这样的话.
我需要运行一个awk脚本来检测频谱中的局部最大值(峰值).该光谱在文本文件中以两列的形式出现.
这是一个较大项目的一部分,该项目将确定这些峰是否代表某些化合物(真正的代谢物).
我搜索了谷歌和无数其他地方我真的找不到任何东西在R中运行awk脚本
编辑:我正在使用的awk脚本看起来像这样 -
awk 'BEGIN{dydx = 0;}
{
if(NR > 1)
{ dydx = ($2 - y0)/($1 - x0); }
if(NR > 2 && last * dydx < 0)
{ printf( "%.4f %.4f\n", (x0 + $1)/2, log((dydx<0)?-dydx:dydx)); } ;
last=dydx; x0=$1; y0=$2
}' /home/chaitanya/Work/nmr_spectra/caffeine/pdata/1/spectrumtext.txt | awk '$2 > 17'
Run Code Online (Sandbox Code Playgroud)
你也可以看到昨天我问的这个问题.请注意,这不是同一个问题.
我为执行CRC编码的程序编写了以下代码.我将它建模在我们课堂上教授的C程序上.它给出了一些我无法纠正的编译错误.我在代码之后提到过它们.
I wrote the following code for a program that performs CRC encoding. I modeled it on a C program that we were taught in class. It gives some compilation errors that I can't correct. I have mentioned them after the code.
1 #include<iostream>
2 #include<string.h>
3
4 using namespace std;
5
6 class crc
7 {
8 char message[128],polynomial[18],checksum[256];
9 public:
10 void xor()
11 {
12 for(int i=1;i<strlen(polynomial);i++)
13 checksum[i]=((checksum[i]==polynomial[i])?'0':'1');
14 }
15 crc() //constructor
16 {
17 …Run Code Online (Sandbox Code Playgroud) 我在回答C中的函数指针如何工作时看到了这个示例代码?
#import <stdlib.h>
#define MAX_COLORS 256
typedef struct {
char* name;
int red;
int green;
int blue;
} Color;
Color Colors[MAX_COLORS];
void eachColor (void (*fp)(Color *c)) {
int i;
for (i=0; i<MAX_COLORS; i++)
(*fp)(&Colors[i]);
}
void printColor(Color* c) {
if (c->name)
printf("%s = %i,%i,%i\n", c->name, c->red, c->green, c->blue);
}
int main() {
Colors[0].name="red";
Colors[0].red=255;
Colors[1].name="blue";
Colors[1].blue=255;
Colors[2].name="black";
eachColor(printColor);
}
Run Code Online (Sandbox Code Playgroud)
该代码返回以下错误:
test.c: In function ‘printColor’:
test.c:21: warning: incompatible implicit declaration of built-in function ‘printf’
Run Code Online (Sandbox Code Playgroud)