first commit
This commit is contained in:
52
2010-06-09/100.cpp
Normal file
52
2010-06-09/100.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
date:107/10/13
|
||||
author:Chen Yi Jing
|
||||
|
||||
如果是奇數做某些事,是偶數就做其他事,有點無聊的題目
|
||||
1. i 的值是要用來跑迴圈的不能改變
|
||||
2. 題目並沒有說 start 會比 end 小
|
||||
*/
|
||||
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
int main() {
|
||||
int start = 0, end = 0, tmp = 1, max = 0, value = 0;
|
||||
int temp = 0;
|
||||
int change = 0;
|
||||
while(cin >> start >> end) {
|
||||
if (start > end) {
|
||||
temp = end;
|
||||
end = start;
|
||||
start = temp;
|
||||
|
||||
change = 1;
|
||||
}
|
||||
|
||||
for (int i = start; i <= end; i++) {
|
||||
value = i;
|
||||
while (value != 1) {
|
||||
if (value % 2 != 0){
|
||||
value = 3 * value + 1;
|
||||
tmp++;
|
||||
}
|
||||
else {
|
||||
value /= 2;
|
||||
tmp++;
|
||||
}
|
||||
}
|
||||
if(tmp > max)
|
||||
max = tmp;
|
||||
|
||||
tmp = 1;
|
||||
}
|
||||
|
||||
if (change == 1) {
|
||||
temp = end;
|
||||
end = start;
|
||||
start = temp;
|
||||
}
|
||||
cout << start << " " << end << " " << max<< endl;
|
||||
max = 0;
|
||||
change = 0;
|
||||
}
|
||||
}
|
30
2010-06-09/10012.cpp
Normal file
30
2010-06-09/10012.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
date:107/10/13
|
||||
author:Chen Yi Jing
|
||||
|
||||
要將一堆圓圈塞進一個長方形裡,求最小長方形面積
|
||||
1. 圓該怎麼擺
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
using namespace std;
|
||||
int main() {
|
||||
int line = 0, n = 0;
|
||||
|
||||
while(cin >> line) {
|
||||
for (int i = 0; i < line; i++) {
|
||||
cin >> n;
|
||||
float num[n];
|
||||
for (int j = 0; j < n; j++) {
|
||||
cin >> num[j];
|
||||
}
|
||||
for (int j = 0; j < n; j++) {
|
||||
cout << num[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cout<< sqrt(1.5*1.5 - 0.5*0.5);
|
||||
}
|
97
2010-06-09/10015.cpp
Normal file
97
2010-06-09/10015.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
date:107/10/13
|
||||
author:Chen Yi Jing
|
||||
|
||||
人圍成圈,用質數去繞圈,質數數完被點到的人會被殺掉,求最後倖存者
|
||||
1. TLE
|
||||
*/
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
//將前 3500 個質數都算出來
|
||||
int p[3502] = {0};
|
||||
int number = 4;
|
||||
int index = 3;
|
||||
|
||||
p[1] = 2;
|
||||
p[2] = 3;
|
||||
|
||||
while (p[3501] == 0) {
|
||||
for (int i = 2; i < number / 2 + 1; i++) {
|
||||
if(number % i == 0) {
|
||||
break;
|
||||
}
|
||||
if(i == number / 2) {
|
||||
p[index] = number;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
number++;
|
||||
}
|
||||
|
||||
|
||||
//輸入的部份
|
||||
int n = 0;
|
||||
int copy_n = 0;
|
||||
|
||||
while(cin >> n) {
|
||||
copy_n = n;
|
||||
|
||||
int point = 0; //用來看現在數到哪個人
|
||||
int counter = 0; //用來倒數質數的
|
||||
int num[n + 1]; //某人是否存活 1:活 0:死
|
||||
|
||||
//初始化為 1
|
||||
for (int k = 0; k <= n; k++) {
|
||||
num[k] = 1;
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
break;
|
||||
|
||||
while (n > 1) { // 存活人數 > 一人
|
||||
for (int i = 1; i < 3501; i++) {
|
||||
if (p[i] % n != 0) {
|
||||
counter = p[i] % n; //如果質數相對人數很大取餘數就好
|
||||
}
|
||||
else {
|
||||
counter = n;
|
||||
}
|
||||
|
||||
// cout << "質數 " << counter << endl;
|
||||
while (counter > 0) {
|
||||
if (point == copy_n) {
|
||||
point = 0;
|
||||
}
|
||||
if (num[point + 1] == 1) {
|
||||
counter--;
|
||||
point++;
|
||||
}
|
||||
else {
|
||||
point++;
|
||||
}
|
||||
|
||||
if (counter == 0) {
|
||||
num[point] = 0; //第 point 人被殺
|
||||
n = n - 1; //總人數少 1
|
||||
// cout << "人數 " << n << endl;
|
||||
}
|
||||
}
|
||||
// cout << "被殺 " << point << endl;
|
||||
// cout <<"---------------"<< endl;
|
||||
if (n == 1)
|
||||
break;
|
||||
}
|
||||
//輸出最後倖存者
|
||||
if (n == 1) {
|
||||
for (int i = 1; i <= copy_n; i++) {
|
||||
if (num[i] == 1)
|
||||
cout << i << endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
}
|
11
2010-06-09/10085.cpp
Normal file
11
2010-06-09/10085.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
date:107/10/13
|
||||
author:Chen Yi Jing
|
||||
|
||||
3 * 3移動拼圖,要變成目標樣子
|
||||
*/
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main () {
|
||||
|
||||
}
|
37
2010-06-09/10579.cpp
Normal file
37
2010-06-09/10579.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
date:107/10/13
|
||||
author:Chen Yi Jing
|
||||
|
||||
Fibonacci Numbers
|
||||
1. Fibonacci Numbers 要的很後面,只能另尋他路owo
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int big_add () {
|
||||
fib = n1 + n2;
|
||||
}
|
||||
int change (int (&n1)[1000]) {
|
||||
|
||||
}
|
||||
int main () {
|
||||
int n = 0;
|
||||
|
||||
while (cin >> n) {
|
||||
int n1[1000], n2[1000], temp[1000], fib[1000];
|
||||
|
||||
if (n == 1)
|
||||
fib[0] = 1;
|
||||
else if (n == 2)
|
||||
fib[0] = 1;
|
||||
else
|
||||
while (n > 2) {
|
||||
|
||||
cout << fib << endl;
|
||||
temp = n2;
|
||||
n2 = fib;
|
||||
n1 = n2;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
}
|
50
2010-06-09/10664.cpp
Normal file
50
2010-06-09/10664.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
date:107/10/13
|
||||
author:Chen Yi Jing
|
||||
|
||||
給很多數字,要判斷這些數字是否能分成兩堆等大的數字
|
||||
1.沒有說一行幾個數字:StringStream 做字串的分割(空白切割)
|
||||
2.動態規劃 0 1 背包的問題:可以用0-1背包的思想来进行解决。
|
||||
先将n个数全部累加起来,总数为sum,这里和0-1背包的不同之处在于,这里的价值和重量是一样的,
|
||||
所以将一个包的容量设置为sum/2,然后你就采用0-1背包思路从n个物品中尽可能的选择数字,
|
||||
使得数字的和最接近sum/2,那么这个解就是最优解。
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
int main() {
|
||||
int n = 0;
|
||||
cin >> n;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
int temp = 0, index = 0;
|
||||
int weight[20] = {0};
|
||||
int sum = 0, str = 0;
|
||||
string input;
|
||||
|
||||
|
||||
getline(cin, input); //取得一行的輸入
|
||||
stringstream ss (input); //StringStream 做字串的分割(空白切割)
|
||||
while(ss >> str) {
|
||||
weight[index] = str;
|
||||
index++;
|
||||
}
|
||||
|
||||
for (int j = 0; j < index; j++) {
|
||||
sum += weight[j];
|
||||
}
|
||||
if (sum % 2 != 0) {
|
||||
cout << "NO" << endl;
|
||||
}
|
||||
else {
|
||||
cout << "YES" << endl;
|
||||
}
|
||||
cout << sum << endl;
|
||||
|
||||
//清空 ss
|
||||
ss.str("");
|
||||
ss.clear();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user