We have a group of N items (represented by integers from 1 to N), and we know that there is some total order defined for these items. You may assume that no two elements will be equal (for all a, b: a<b or b<a). However, it is expensive to compare two items. Your task is to make a number of comparisons, and then output the sorted order. The cost of determining if a < b is given by the bth integer of element a of costs (space delimited), which is the same as the ath integer of element b. Naturally, you will be judged on the total cost of the comparisons you make before outputting the sorted order. If your order is incorrect, you will receive a 0. Otherwise, your score will be opt/cost, where opt is the best cost anyone has achieved and cost is the total cost of the comparisons you make (so your score for a test case will be between 0 and 1). Your score for the problem will simply be the sum of your scores for the individual test cases.
標簽:
represented
integers
group
items
上傳時間:
2016-01-17
上傳用戶:jeffery
The XML Toolbox converts MATLAB data types (such as double, char, struct, complex, sparse, logical) of any level of nesting to XML format and vice versa.
For example,
>> project.name = MyProject
>> project.id = 1234
>> project.param.a = 3.1415
>> project.param.b = 42
becomes with str=xml_format(project, off )
"<project>
<name>MyProject</name>
<id>1234</id>
<param>
<a>3.1415</a>
<b>42</b>
</param>
</project>"
On the other hand, if an XML string XStr is given, this can be converted easily to a MATLAB data type or structure V with the command V=xml_parse(XStr).
標簽:
converts
Toolbox
complex
logical
上傳時間:
2016-02-12
上傳用戶:a673761058
#include <stdio.h>
#include <stdlib.h>
#define SMAX 100
typedef struct SPNode
{
int i,j,v;
}SPNode;
struct sparmatrix
{
int rows,cols,terms;
SPNode data [SMAX];
};
sparmatrix CreateSparmatrix()
{
sparmatrix A;
printf("\n\t\t請輸入稀疏矩陣的行數,列數和非零元素個數(用逗號隔開):");
scanf("%d,%d,%d",&A.cols,&A.terms);
for(int n=0;n<=A.terms-1;n++)
{
printf("\n\t\t輸入非零元素值(格式:行號,列號,值):");
scanf("%d,%d,%d",&A.data[n].i,&A.data[n].j,&A.data[n].v);
}
return A;
}
void ShowSparmatrix(sparmatrix A)
{
int k;
printf("\n\t\t");
for(int x=0;x<=A.rows-1;x++)
{
for(int y=0;y<=A.cols-1;y++)
{
k=0;
for(int n=0;n<=A.terms-1;n++)
{
if((A.data[n].i-1==x)&&(A.data[n].j-1==y))
{
printf("%8d",A.data[n].v);
k=1;
}
}
if(k==0)
printf("%8d",k);
}
printf("\n\t\t");
}
}
void sumsparmatrix(sparmatrix A)
{
SPNode *p;
p=(SPNode*)malloc(sizeof(SPNode));
p->v=0;
int k;
k=0;
printf("\n\t\t");
for(int x=0;x<=A.rows-1;x++)
{
for(int y=0;y<=A.cols-1;y++)
{
for(int n=0;n<=A.terms;n++)
{
if((A.data[n].i==x)&&(A.data[n].j==y)&&(x==y))
{
p->v=p->v+A.data[n].v;
k=1;
}
}
}
printf("\n\t\t");
}
if(k==1)
printf("\n\t\t對角線元素的和::%d\n",p->v);
else
printf("\n\t\t對角線元素的和為::0");
}
int main()
{
int ch=1,choice;
struct sparmatrix A;
A.terms=0;
while(ch)
{
printf("\n");
printf("\n\t\t 稀疏矩陣的三元組系統 ");
printf("\n\t\t*********************************");
printf("\n\t\t 1------------創建 ");
printf("\n\t\t 2------------顯示 ");
printf("\n\t\t 3------------求對角線元素和");
printf("\n\t\t 4------------返回 ");
printf("\n\t\t*********************************");
printf("\n\t\t請選擇菜單號(0-3):");
scanf("%d",&choice);
switch(choice)
{
case 1:
A=CreateSparmatrix();
break;
case 2:
ShowSparmatrix(A);
break;
case 3:
SumSparmatrix(A);
break;
default:
system("cls");
printf("\n\t\t輸入錯誤!請重新輸入!\n");
break;
}
if (choice==1||choice==2||choice==3)
{
printf("\n\t\t");
system("pause");
system("cls");
}
else
system("cls");
}
}
標簽:
數組
子系統
上傳時間:
2020-06-11
上傳用戶:ccccy