Monday, January 18, 2016
Solved UVA problem (code for bad horse using c/C++ programming)
using namespace std;
class Node{
public:
string name;
vector
bool visited;
int groupId;
Node(string str):name(str), visited(false), groupId(-1){}
int getNeighborCount(){
return adj.size();
}
};
class graph{
public:
unordered_map
vector
void createNode(string str){
Node* n = new Node(str);
nodes.push_back(n);
hashNode[str] = n;
}
};
int main()
{
freopen("A-small-practice-1.in", "r", stdin);
freopen("A-small-practice-1.out", "w", stdout);
int input_count;
cin>>input_count;
int counter = 1;
while(input_count)
{
int M;
cin>>M;
graph G;
for(int i=0;i
string str1, str2;
cin>>str1>>str2;
g.AddEdge(str1,str2);
}
cout<<"Case #"<
}
return 0;
}
Solved uva programming problem Jolly Jumper C/C++ code Solution
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pi acos(-1.0)
#define N 1000000
#define long long LL
using namespace std;
int num[3010],n;
int diff[3005];
int k;
main()
{
while(scanf("%d", &n)){
for(int i=0;i
k=1;
for(int i =1; i
sort(diff+1,diff+k);
bool yap=true;
for(int i=1;i
yap = false;
break;
}
}
if(yap) cout<<"Jolly"<
}
UVA 102 Ecological bin solved problem c/c++
// @BEGIN_OF_SOURCE_CODE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pi acos(-1.0)
#define N 1000000
#define long long LL
using namespace std;
int bottles [9 + 3];
int count_movement (int a, int b, int c)
{
int m = 0;
for ( int i = 0; i < 9; i++ ) {
if ( i != a && i != b && i != c )
m += bottles [i];
}
return m;
}
int main ()
{
while ( scanf ("%d", &bottles [0]) != EOF ) {
for ( int i = 1; i < 9; i++ )
scanf ("%d", &bottles [i]);
char output_str [3 + 3];
int movements [6];
int min_movement = INT_MAX;
char combinations [6] [3 + 2] = {"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"};
// Brown index : 0 3 6
// Green index : 1 4 7
// Clear index : 2 5 8
movements [0] = count_movement (0, 5, 7); // BCG
movements [1] = count_movement (0, 4, 8); // BGC
movements [2] = count_movement (2, 3, 7); // CBG
movements [3] = count_movement (2, 4, 6); // CGB
movements [4] = count_movement (1, 3, 8); // GBC
movements [5] = count_movement (1, 5, 6); // GCB
for ( int i = 0; i < 6; i++ ) {
if ( movements [i] < min_movement ) {
min_movement = movements [i];
strcpy (output_str, combinations [i]);
}
}
printf ("%s %d\n", output_str, min_movement);
}
return 0;
}
// @END_OF_SOURCE_CODE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pi acos(-1.0)
#define N 1000000
#define long long LL
using namespace std;
int bottles [9 + 3];
int count_movement (int a, int b, int c)
{
int m = 0;
for ( int i = 0; i < 9; i++ ) {
if ( i != a && i != b && i != c )
m += bottles [i];
}
return m;
}
int main ()
{
while ( scanf ("%d", &bottles [0]) != EOF ) {
for ( int i = 1; i < 9; i++ )
scanf ("%d", &bottles [i]);
char output_str [3 + 3];
int movements [6];
int min_movement = INT_MAX;
char combinations [6] [3 + 2] = {"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"};
// Brown index : 0 3 6
// Green index : 1 4 7
// Clear index : 2 5 8
movements [0] = count_movement (0, 5, 7); // BCG
movements [1] = count_movement (0, 4, 8); // BGC
movements [2] = count_movement (2, 3, 7); // CBG
movements [3] = count_movement (2, 4, 6); // CGB
movements [4] = count_movement (1, 3, 8); // GBC
movements [5] = count_movement (1, 5, 6); // GCB
for ( int i = 0; i < 6; i++ ) {
if ( movements [i] < min_movement ) {
min_movement = movements [i];
strcpy (output_str, combinations [i]);
}
}
printf ("%s %d\n", output_str, min_movement);
}
return 0;
}
// @END_OF_SOURCE_CODE
Subscribe to:
Posts (Atom)