├── .gitignore ├── README.md ├── .gitattributes ├── Dijkstra.cpp └── 加勒比海盗问题.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *exe 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AlgorithmCode 2 | >此文档是练习算法 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Dijkstra.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | const int N = 100; 8 | //const int INF = 1e7; 9 | using namespace std; 10 | bool flag[N]; 11 | int main() 12 | { 13 | printf("123"); 14 | 15 | } -------------------------------------------------------------------------------- /加勒比海盗问题.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | const int N = 1000005; 5 | using namespace std; 6 | double w[N]; //古董的重量 7 | int main() 8 | { 9 | double c; 10 | int n; 11 | cout << "请输入古董重量c及古董个数n: " << endl; 12 | cin >> c >> n; 13 | cout << "请输入每个古董的重量,用空格分隔开: " << endl; 14 | for (int i = 0; i < n; i++) 15 | { 16 | cin >> w[i]; 17 | } 18 | sort(w, w + n); 19 | double weight = 0.0; 20 | int ans = 0; 21 | for (int i = 0; i < n; i++) 22 | { 23 | weight += w[i]; 24 | if (weight <= c) 25 | ans++; 26 | else 27 | break; 28 | } 29 | cout << "能装入的古董最大数量为Ans= "; 30 | cout << ans << endl; 31 | return 0; 32 | } --------------------------------------------------------------------------------