1
0
Fork 0

Add NTU/{pali2,editpic}.c and update README.md

This commit is contained in:
Nguyễn Gia Phong 2017-01-09 10:47:37 +07:00
parent 15b38076cc
commit 318184dbda
13 changed files with 109 additions and 13 deletions

View File

@ -7,7 +7,7 @@
- [x] writer: [Robot đánh chữ](http://laptrinh.ntu.edu.vn/Problem/Details/3255)
- [x] ngto4: [Tổng nguyên tố](http://laptrinh.ntu.edu.vn/Problem/Details/3256)
- [x] demso0: [Đếm số không bên phải](http://laptrinh.ntu.edu.vn/Problem/Details/3330)
- [ ] pali2: [Tách chuỗi đối xứng](http://laptrinh.ntu.edu.vn/Problem/Details/3332)
- [x] pali2: [Tách chuỗi đối xứng](http://laptrinh.ntu.edu.vn/Problem/Details/3332)
- [x] moco: [Khu mộ cổ](http://laptrinh.ntu.edu.vn/Problem/Details/3343)
- [x] dayso6: [Dãy số](http://laptrinh.ntu.edu.vn/Problem/Details/3344)
- [x] keba2: [Kết bạn](http://laptrinh.ntu.edu.vn/Problem/Details/3345)
@ -25,6 +25,6 @@
- [ ] hamar: [Hàm số](http://laptrinh.ntu.edu.vn/Problem/Details/5557)
- [x] xauduynhat: [Xâu duy nhất](http://laptrinh.ntu.edu.vn/Problem/Details/5573)
- [x] chenhlech: [Chênh lệch](http://laptrinh.ntu.edu.vn/Problem/Details/5574)
- [ ] editpic: [Chỉnh sửa ảnh](http://laptrinh.ntu.edu.vn/Problem/Details/5588)
- [x] editpic: [Chỉnh sửa ảnh](http://laptrinh.ntu.edu.vn/Problem/Details/5588)
- [ ] cntpalin: [Đếm số Palindrome](http://laptrinh.ntu.edu.vn/Problem/Details/5600)
- [x] TutOnEqua: [Tutoring on equations](http://laptrinh.ntu.edu.vn/Problem/Details/5606)

30
NTU/editpic.c Normal file
View File

@ -0,0 +1,30 @@
#include <stdio.h>
const long long POW2[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
4096, 8192, 16384, 32768, 65536, 131072, 262144,
524288, 1048576, 2097152, 4194304, 8388608, 16777216,
33554432, 67108864, 134217728, 268435456, 536870912};
int main()
{
long long l, w, l0, w0, l1, w1;
char i;
scanf("%lld %lld", &l, &w);
for (i = 29; POW2[i] > l || POW2[i] * 4 > w * 5; i--);
l0 = POW2[i];
w0 = (l0 * 5 >= w * 4) ? w : l0 * 5 / 4;
for (i = 29; POW2[i] > w || POW2[i] * 4 > l * 5; i--);
w1 = POW2[i];
l1 = (w1 * 5 >= l * 4) ? l : w1 * 5 / 4;
l = l0 * w0 - l1 * w1;
if (l > 0 || !l && l0 > l1)
printf("%lld %lld\n", l0, w0);
else
printf("%lld %lld\n", l1, w1);
return 0;
}

68
NTU/pali2.c Normal file
View File

@ -0,0 +1,68 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
short MIN_K, *P;
void putnc(char *s, short len)
{
short i;
for (i = 0; i < len; i++)
putchar(s[i]);
putchar(10);
}
char palin(char *s, short len)
{
short i;
for (i = 0; i < (len + 1) / 2; i++)
if (s[i] != s[len - i - 1])
return 0;
return 1;
}
void foo(char *s, short len, short k, short *p)
{
short i, j;
if (palin(s, len)) {
MIN_K = k;
memcpy(P, p, k * sizeof(short));
return;
}
if (k >= MIN_K)
return;
for (i = len - 1; i; i--)
if (palin(s, i)) {
p[k] = p[k - 1] + i;
foo(s + i, len - i, k + 1, p);
}
}
int main()
{
short n, i, *p;
char *s;
scanf("%hd\n", &n);
s = malloc(n + 1);
fgets(s, n + 1, stdin);
MIN_K = n;
P = malloc(n);
p = malloc(n);
p[0] = 0;
foo(s, n, 1, p);
printf("%hd\n", MIN_K);
for (i = 1; i < MIN_K; i++)
putnc(s + P[i - 1], P[i] - P[i - 1]);
puts(s + P[MIN_K - 1]);
return 0;
}

View File

@ -2,15 +2,15 @@
Bài tập luyện tập thi Olympic, học sinh giỏi Tin học, trong đó:
| Thư mục | Nguồn đề bài |
| --------------------- | --------------------------------- |
| `9`, `10`, `11`, `12` | Đề thi, kiểm tra phân theo lớp |
| `COCI` | [Giải Tin học Croatia mở rộng][0] |
| `NTU` | [Đại học Nha Trang][1] |
| `THT` | Hội thi Tin học trẻ |
| `codeforces` | [Codeforces][2] |
| `daily` | [/r/dailyprogrammer][3] |
| `others` | Các đề bài không rõ nguồn |
| Thư mục | Nguồn đề bài |
| ---------------------- | --------------------------------- |
| `09`, `10`, `11`, `12` | Đề thi, kiểm tra phân theo lớp |
| `COCI` | [Giải Tin học Croatia mở rộng][0] |
| `NTU` | [Đại học Nha Trang][1] |
| `THT` | Hội thi Tin học trẻ |
| `codeforces` | [Codeforces][2] |
| `daily` | [/r/dailyprogrammer][3] |
| `others` | Các đề bài không rõ nguồn |
[0]: http://www.hsin.hr/coci/
[1]: http://laptrinh.ntu.edu.vn/
@ -24,8 +24,6 @@ nhật dần.
Bài làm trên Pascal được được dịch thử trên FPC 2.6 trở lên, bài viết trên C
được dịch trên GCC 6 trở lên, bài làm trên Python chạy thử trên Python 3.5.
Các commit message có dạng: `<đường dẫn>: <Nội dung thay đổi>`.
Tất cả các bài làm được phát hành theo giấy phép [GPLv3](LICENSE), cho phép
người dùng chạy, nghiên cứu, chia sẻ và chỉnh sửa tự do. Các đề bài hầu như
không rõ điều khoản sử dụng.