Posted by: dzikrina on: January 22, 2010
http://acm.tju.edu.cn/toj/vcontest/contest5472.html
PROBLEM B
B. Serious Cow Tag
/*
TASK:
LANG: C++
USER: smilitude1
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct data { int x,y; } ;
int main() {
data d[1005];
int n;
bool ok[1005]; SET( ok, 0 );
scanf(“%d”,&n);
for(int i=0; i<n; i++) scanf("%d %d",&d[i].x, &d[i].y);
int st = -1;
for(int t=0; t<n-1; t++) {
int mindist, id;
mindist = -1;
++ st, st %= n;
while( ok[ st ] ) ++st, st %= n;
for(int i=0; i<n; i++) if( !ok[i] && i != st ) {
int dist = ( d[i].x – d[st].x ) * ( d[i].x – d[st].x ) + ( d[i].y – d[st].y ) * ( d[i].y – d[st].y );
if( mindist == -1 || dist < mindist ) mindist = dist, id = i;
}
ok[ id ] = true;
}
for(int i=0; i<n; i++) if( !ok[i] ) printf("%d\n",i+1);
return 0;
}
PROBLEM C
The Flower Garden
#include
using namespace std;
int main()
{
// freopen(“in.txt”,”r”,stdin);
// freopen(“out.txt”,”w”,stdout);
int row,garden[10010],numr;
int sslot, seq, count=0;
cin >> row;
cin >> numr;
for (int j=0; j<row; j++) garden[j]=0;
for (int i=0; i> sslot;
cin >> seq;
for (int k=(sslot-1); k<row; k+=seq)
garden [k]=1;
}
int ans = 0;
for(int i=0; i<row; i++) if( garden[i] == 0 ) ans ++;
cout << ans << endl;
return 0;
}
PROBLEM D
Sudoku
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main() {
int total, nflower;
while( scanf(“%d%d”,&total, &nflower ) == 2 ) {
bool flag[total+1];
int a,b;
memset( flag, 0, sizeof( flag ));
for(int i=0; i<nflower; i++) {
scanf("%d%d",&a, &b );
for(int j=a; j<=total; j+=b) flag[j] = true;
}
int ans = 0;
for(int i=1; i<=total; i++) if(flag[i] == 0 ) ans++;
printf("%d\n",ans);
}
return 0;
}
PROBLEM E
RED AND BLACK
/*
TASK: TJU 1851
ALGO: backtracking
LANG: C++
USER: smilitude
TIME:
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for( __typeof(b) i=(a); i=(b); i–)
#define SET(t,v) memset((t), (v), sizeof(t))
#define sz size()
#define pb push_back
#define i64 long long
#define ALL(x) x.begin(), x.end()
#define FORIT(i, m) for (__typeof((m).begin()) i=(m).begin(); i!=(m).end(); ++i)
#define REV(x) reverse( ALL( x ) )
#define IO freopen(“”,”r”,stdin); freopen(“”,”w”,stdout);
#define bug(x) cerr << __LINE__ <<" "<< #x " = " << x << endl
char g[10][10];
int used[3][3][10], row[9][10], col[9][10];
bool done;
int mid = 15;
void print() {
REP(i,9) {
REP(j,9) printf("%d", g[i][j] );
puts("");
}
// puts("");
}
void solve( int r, int c ) {
if( r == 9 ) {
done = 1;
print();
}
else if( c == 9 ) solve( r+1, 0 );
else if( g[r][c] != 0 ) solve( r, c+1 );
else {
int rr = r/3, cc = c/3;
FOR(i,1,9) {
if( row[r][i] || col[c][i] || used[rr][cc][i] ) continue;
row[r][i] = 1;
col[c][i] = 1;
used[rr][cc][i] = 1;
g[r][c] = i;
solve( r, c+1 );
if( done ) return;
row[r][i] = 0;
col[c][i] = 0;
used[rr][cc][i] = 0;
}
g[r][c] = 0;
}
}
int main() {
int t;
scanf("%d",&t);
while( t– ) {
REP(i,9) scanf("%s",g[i]);
// building
SET( used, 0 ); SET( row, 0 ); SET( col, 0 );
REP(r,9) REP(c,9) {
if( g[r][c] == '0' ) g[r][c] = 0;
else {
g[r][c] -= '0';
row[r][ g[r][c] ] = 1;
col[c][ g[r][c] ] = 1;
used[ r/3 ][ c/3 ][ g[r][c] ] = 1;
}
}
// processing
done = 0;
solve(0,0);
}
return 0;
}
ALL THE CODES BY MY TUTORS, BRO IQRAM N BRO EMIR
IIUM PROGRAMMING TRAINING 2010
Posted by: dzikrina on: January 22, 2010
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int a[205], b[205];
int na, nb;
int main() {
int t;
cin >> t;
while( t– ) {
cin >> na;
for(int i=0; i> a[i];
cin >> nb;
for(int i=0; i> b[i];
int ans = 0;
for(int i=0; i<na; i++)
for(int j=0; j<nb; j++)
if( (a[i] + b[j]) == 0 ) ans++;
cout << ans << endl;
}
return 0;
}
Posted by: dzikrina on: December 21, 2009
fourth class
here are some sample of html expertise:
Here’s some big text
Here’s some smaller text
And here’s a new paragraph to round things out.
this text is center
this is the example of the paragraph and make it right
this is the example of the paragraph and make it left
this is the example of the paragraph and make it center
This is a default order list
This is a big letter order list
This is a small letter order list
This is a default unorder list
This is a nested unorder list
This is a square unorder list
This is a circle list
Posted by: dzikrina on: December 19, 2009
// 1001 HELLO WORLD!
#include <iostream>
using namespace std;
int main()
{
int num;
while (scanf (“%d”, &num) != EOF)
{
char C = static_cast<char> (num);
cout << C;
}
cout << endl;
system (“pause”);
return 0;
}
Posted by: dzikrina on: December 19, 2009
// QUICK CHANGE OR FAST CHANGE
#include <iostream>
using namespace std;
int main()
{
int numCase;
int change;
int quarter, dime, nickel, penny;
int Q, D, N, P;
int rem1, rem2, rem3;
#define QUARTER 0.25
#define DIME 0.10
#define NICKEL 0.05
#define PENNY 0.01
#define BASE 100
Q = static_cast <int> (BASE*QUARTER);
D = static_cast <int> (BASE*DIME);
N = static_cast <int> (BASE*NICKEL);
P = static_cast <int> (BASE*PENNY);
cin >> numCase;
for (int i=0; i<numCase; i++)
{
cin >> change;
quarter = (change/Q);
rem1 = (change%Q);
dime = (rem1/D);
rem2 = (rem1%D);
nickel = (rem2/N);
rem3 = (rem2%N);
penny = (rem3/P);
cout << i+1 <<” “<< quarter << ” QUARTER(S), ” << dime << ” DIME(S), ” << nickel <<” NICKEL(S), “
<< penny << ” PENNY(S)” << endl;
}
return 0;
}
Posted by: dzikrina on: December 19, 2009
Factors and divisors are synonyms.
SOD(N) is equal to sum of factors of N.
For example SOD(20) = 1 + 2 + 4 + 5 + 10 + 20 = 42
Given an integer N, find its SOD().
Input
The first line of input is the number of test cases. Each case is an integer N(N<=10000).
Output
For each case, output the case number followed by the result
Sample Input
2
20
1
Sample Output
Case 1: 42
Case 2: 1
ANSWER
#include <iostream>
using namespace std;
int main()
{
int N, numCase, sum;
cin >> numCase;
for (int i=0; i<numCase; i++)
{
cin >> N;
sum=0;
for (int j=1; j<N+1; j++)
{
if (N%j == 0)
sum = sum + j;
}
cout << “Case ” << i+1 << “: ” << sum << endl;
}
return 0;
}
Posted by: dzikrina on: December 19, 2009
// 11636 Hello World!
#include
using namespace std;
int main()
{
int mycase=0, N;
double k;
while (1)
{
cin >> N;
if (N <0)
break;
k = ceil(log(N)/log(2));
int i=0;
mycase ++;
cout <<”Case ” << mycase << “:” << k << endl;
}
return 0;
}
Posted by: dzikrina on: December 19, 2009
// SIXTH GRADE MATH
#include <iostream>
using namespace std;
int GCD (int num1, int num2);
int LCM (int num1, int num2);
int main()
{
int numCase;
int num1, num2, k;
cin >> numCase;
for (int i=0; i<numCase; i++)
{
cin >> num1 >> num2;
cout << i+1 <<” ” << LCM (num1, num2) <<” ” << GCD (num1, num2) << endl;
}
return 0;
}
int GCD (int num1, int num2)
{
while (num2 != 0)
{
int t = num2;
num2 = num1%num2;
num1 = t;
}
return num1;
}
int LCM (int num1, int num2)
{
int k;
k = (num1*num2) / GCD(num1, num2);
return k;
}
Posted by: dzikrina on: October 15, 2008
#include <iostream>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <fstream>
using namespace std;
int size;
int Random(int n)
{
srand(time(NULL));
return ((rand()*10000)%(size-1));
}
int main()
{
ofstream original("string.txt");
ofstream shuffleOut("shuffle.txt");
cout << "Begin file creation\n";
// original.open
// shuffleOut.open("shuffle.txt");
cout<<"Insert how many words"<<endl;
cin>>size;
int mynum[size];
string word[size];
cout<<"Please insert the words that you want to scramble"<<endl;
for(int p=0;p<size;p++)
cin>>word[p];
cout<<endl;
cout<<"Original word...."<<endl;
for(int q=0;q<size;q++)
{
cout<<word[q]<<" ";
original<<word[q]<<" ";
}
char answer='n';
int iteration=0;
do
{
cout<<endl
<<"Scrambling character(s)..."<<endl;
iteration++;
for (int i=size;i>=0;i--)
{
std::random_shuffle(word,word+(size),Random);
}
cout<<endl;
cout<<"Iteration #"<<iteration<<endl;
for(int m=0;m<size;m++)
{
cout<<word[m]<<" ";
shuffleOut<<word[m]<<" ";
}
cout<<endl;
cout<<"Reshuffle?"<<endl;
cin>>answer;
if(answer=='n'||answer=='N')
{
cout<<"Stop at iteration #"<<iteration<<endl;
cout<<"Thank you!"<<endl;
// original.close("string.txt");
// shuffleOut.close("shuffle.txt");
}
shuffleOut<<'\n';
}while(answer=='y'||answer=='Y');
cout<<endl;
system("pause");
return 0;
}
Posted by: dzikrina on: September 11, 2008
/* Array, insert marks for x quizes for two subjects
find out how many marks in particular subject greater than the other
*/
# include <iostream>
using namespace std;
int main ()
{
int x,i;
int prog [x];
int math [x];
int qprog=0;
int qmath=0;
cout << “How many quiz that you want to evaluate?” << endl;
cin >> x;
cout << “Insert marks for math” << endl;
for (int i=0; i<x; i++)
{
cin >> math [x];
}
cout << “Insert marks for programming” << endl;
for (int i=0; i<x; i++)
{
cin >> prog [x];
}
for (i=0; i < x; i++)
{
if (prog [x] > math [x])
qprog ++;
else if (prog [x] < math [x])
qmath++;
else;
}
cout << qmath<< endl;
cout << qprog<< endl;
if (qmath > qprog)
cout << “Your score better on math for ” << qmath << “number of quiz(es)”<< endl;
else if (qmath < qprog)
cout << “Your score better on programming quiz ” << qprog << “number of quiz(es)” << endl;
else
cout << “Same” << endl;
system (“pause”);
return 0;
}
Recent Comments