#include <stdio.h>
int main() {
int s;
scanf("%d",&s);
while(s--) {
int r,c,x=0,p=1;
scanf("%d",&c);
do x += (r = c/(p*=5)); while(r);
printf("%d\n",x);
}
return 0;
}
Mar 26, 2010
Solution for problem code FCTRL on SPOJ
Jan 18, 2010
PHP: calculate distance between two points
Each point is an one-dimensional array, each value in the array is a coordinate, so dimension of coordinates in this function is arbitriary.
/*
* Calculates Euclidian distance between two points in p-norm
* Points $p1 and $p2 are Nx1 matrices
*/
function euclidian_distance($p1,$p2) {
if(count($p1) != count($p2)) return false;
$distances = 0;
$p1 = array_values($p1);
$p2 = array_values($p2);
$norm = count($p2);
for($i=0;$i<$norm;$i++) $distances += pow(abs($p1[$i]-$p2[$i]),2);
return pow($distances,1/2);
}
Jan 8, 2010
Windows 7/Vista & ArcGIS & ESRI License Manager
It seems that ESRI License Manager has difficulties running in Windows 7 or Vista – the License server fails to start at boot or on demand in License Manager Tools.
Consequently, ArcGIS didn’t start because there was no license server running. Obviously this problem doesn’t occur if the license server is running on another machine in the network.
At first I tried the quick and dirty solution – to manually start the server daemon and see where it fails.
I ran Command Prompt as an administrator:
Now, the server is called lmgrd.exe, so if you navigate to C:\Program Files\ESRI\License\arcgis9x and start lmgrd, it says that there is no license specified.
So I typed the location of the license (it was in the same folder), ran the program in the foreground:
lmgrd –c license.lic -z
I kept the command prompt open, and ArcGIS started succesfully.
But this isn’t really a long term solution, since this method would require manual server start in the command prompt everytime I would want to start ArcGIS.
So I thought, maybe the problem is that the server can’t find the license file. After some googling, I found out that the environment variable LM_LICENSE_FILE wasn’t set. It says on the support page that you’d need to enter port@machine-name for the variable value, but since we’re running the server on the local machine, you just need to enter your C:\Path\to\your\license.lic.
When all goes well with License Manager Tools, you might still need to enter "localhost" in the ArcGIS desktop manager in the license server.
If anyone has a better solution or information, please post in the comments.
UPDATE:
After further experimentation I found out that you also need the Sentinel driver to successfuly run License Manager on Windows 7. Don't know why, but it works. You should install Sentinel driver first, then the license manager, so that everything for the license works before you install ArcGIS. That way you won't have to manually configure ArcGIS for license after it has been installed. You have less work that way.
Consequently, ArcGIS didn’t start because there was no license server running. Obviously this problem doesn’t occur if the license server is running on another machine in the network.
At first I tried the quick and dirty solution – to manually start the server daemon and see where it fails.
I ran Command Prompt as an administrator:
Now, the server is called lmgrd.exe, so if you navigate to C:\Program Files\ESRI\License\arcgis9x and start lmgrd, it says that there is no license specified.
So I typed the location of the license (it was in the same folder), ran the program in the foreground:
lmgrd –c license.lic -z
I kept the command prompt open, and ArcGIS started succesfully.
But this isn’t really a long term solution, since this method would require manual server start in the command prompt everytime I would want to start ArcGIS.
So I thought, maybe the problem is that the server can’t find the license file. After some googling, I found out that the environment variable LM_LICENSE_FILE wasn’t set. It says on the support page that you’d need to enter port@machine-name for the variable value, but since we’re running the server on the local machine, you just need to enter your C:\Path\to\your\license.lic.
When all goes well with License Manager Tools, you might still need to enter "localhost" in the ArcGIS desktop manager in the license server.
If anyone has a better solution or information, please post in the comments.
UPDATE:
After further experimentation I found out that you also need the Sentinel driver to successfuly run License Manager on Windows 7. Don't know why, but it works. You should install Sentinel driver first, then the license manager, so that everything for the license works before you install ArcGIS. That way you won't have to manually configure ArcGIS for license after it has been installed. You have less work that way.
Dec 25, 2009
Quick Tip: light switch effect
Here's a quick tip for novice programmers. Every time you want to create a "light-switch" effect for toggling a parameter on and off, or should I say true or false, 0 or 1, ...
You can simply do it by typing:
We see that if our b variable is 1 (true) the result of a ^ 1 (a XOR 1) is exactly the opposite of a.
All in all, this operation is simply a shortcut for these assignments:
p ^= 1;
This is a binary-safe Exclusive-OR assignment operator. First, it computes the value of p XOR 1 (p = p ^ 1) and then stores that value in p.
If we look at the truth table of exclusive-or (XOR)
| a | b | a XOR b |
| 0 | 0 | 0
|
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
p = p ^ 1; p = !p; p = p ? false : true; if(p) p = false; else p = true;So if you want to toggle something ON and OFF, let's say when a user clicks a button, this method is extremely short and useful.
Dec 20, 2009
Facebook Connect: FB.Connect.streamPublish() does not show up
DUE TO FREQUENT FACEBOOK API CHANGES THIS ARTICLE IS OUTDATED.
Here are the reasons why FBJS functions sometimes fail:
Here are the reasons why FBJS functions sometimes fail:
- xd_reciever.html is not installed correctly
- application key is not set in FB.init()
- Facebook Connect callback URL is not set in the application settings
- Facebook JavaScript API is not set correctly in your HTML. This should be set immediately after the body tag <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script> This should be set before the closing body tag <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US" type="text/javascript"></script>
- Facebook functions are called before JavaScript objects are initialized. FB.init(api_key, channel_path); FB.ensureInit(function() { // put your functions here });
- All Facebook JavaScript functions are called BEFORE the FeatureLoader.js.php You should put your functions after this call and into FB.ensureInit() function
- There are JavaScript errors in your code
Subscribe to:
Posts (Atom)