#include <iostream> #include <cstdio> #define ul unsigned long long//double//long long using namespace std; int main() { ul s,d,a,b; ul subtract; ul lw,hi,mid,res; while(scanf("%llu%llu",&s,&d)!=EOF) { if(d<=s) { printf("%llu\n",s); continue; } subtract=(s*(s-1))/2; lw=s; hi=s+d/s; res=-1; while(hi-lw>1) { mid=(lw+hi)/2; if(((mid*(mid+1))/2-subtract) <d) lw=mid+1; else if(((mid*(mid+1))/2-subtract)>d) hi=mid; else if(((mid*(mid+1))/2-subtract)==d) { res=mid; break; } } if(res!=-1) printf("%llu\n",res); else { //cout<<lw<<" "<<hi<<"\n";
Month: April 2016
974
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <vector> #define ll long long using namespace std; ll arr[40001]; vector<int> vb; ll _pow(int pwr) { if(pwr==0) return 1; else return 10*_pow(pwr-1); } bool Isfunc(ll a,int b) { int tmp; tmp=a; int pwr=0; int num=0; while(tmp) { num=num + (tmp%10)*_pow(pwr); tmp/=10; if(tmp+num==b && tmp!=0 && num!=0)
696
#include <iostream> #include <cstdio> using namespace std; int main() { int r,c,tmp,res; int row,col; //FILE *fp; //fp=fopen("out.txt","w"); while(scanf("%d%d",&r,&c)) { if(r+c==0) break; if((r==1 || c==1) || r==0 || c==0) { printf("%d knights may be placed on a %d row %d column board.\n",r*c,r,c); //fprintf(fp,"%d knights may be placed on a %d row %d column board.\n",r*c,r,c); continue; }
661
#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; int capacity[21]; bool isTurnOn[21]; int main() { int n,m,c; int MX=0; int device; int kase=1; bool IsFUSE; long long total; while(scanf("%d%d%d",&n,&m,&c)) { if(n+m+c==0) break; //memset(capacity,0,sizeof(capacity)); //memset(isTurnOn,0,sizeof(isTurnOn)); IsFUSE=0; for(int i=1;i<=n;i++) { scanf("%d",&capacity[i]); isTurnOn[i]=0; } total=0; MX=0; for(int i=1;i<=m;i++) { scanf("%d",&device); if(IsFUSE) continue; if(isTurnOn[device]==0) { isTurnOn[device]=1;
594
#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; int main() { int n,res; int positionInByte,byteNo; while(scanf("%d",&n)!=EOF) { res=0; for(int i=0;i<32;i++) { if((1<<i)&n) { byteNo=i/8; positionInByte=i%8; res |= (1<<((3-byteNo)*8+positionInByte)); } } printf("%d converts to %d\n",n,res); } return 0; }
474
There is a problem with online judge results for this problem. It accepts for n=6 as AC result as : 2^-6 = 1.562e-2 and for n=7 AC result as : 2^-7 = 7.812e-3 But it should be 2^-6 = 1.563e-2 and 2^-7 = 7.813e-3 respectively using approximation method after 3rd decimal. So to get AC from UVA OJ I
471
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <vector> #define ll long long #define LIMIT 9876543210 using namespace std; vector<int> vb; bool isRepeated(ll num) { if(num>=0 && num<=10) return 0; bool digits[10]; memset(digits,0,sizeof(digits)); while(num) { if(digits[num%10]) return 1; digits[num%10]=1; num/=10; } return 0; } int main() { int t; ll n; ll num; for(int
460
#include <iostream> #include <cstdlib> #include <cmath> #include <cstdio> using namespace std; struct point{ int x,y; }; point LL1,LL2,LR1,LR2,UL1,UL2,UR1,UR2; point New_LL,New_LR,New_UL,New_UR; bool isOverlap() { if(LL1.x>=LR2.x) return 0; if(LR1.x<=LL2.x) return 0; if(LL1.y>=UL2.y) return 0; if(UL1.y<=LL2.y) return 0; return 1; } bool isTotalInside() { if((LL1.x>=LL2.x && LL1.x <= UR2.x) && (LL1.y>=LL2.y && LL1.y <= UR2.y)) { if((LR1.x>=LL2.x &&
107
#include <iostream> #include <cstdio> #include <cmath> #include <vector> #define ll long long #define MOD 1000000007 using namespace std; int _pow(int n,int p) { if(p==0) return 1; else return n*_pow(n,p-1); } int isAnyRoot(int a,int b) { if(a%b!=0) return -1; int cnt=0; while(a>=b) { cnt+=1; a=a/b; if(a>=b && a%b!=0) return -1; } return cnt; } int main()
278
#include <iostream> #include <cstdio> using namespace std; int main() { int t; int row,col; char ch,c; scanf("%d%c",&t,&ch); while(t–) { scanf("%c%d%d%c",&ch,&row,&col,&c); if(ch=='r') { printf("%d\n",(row<=col?row:col)); } else if(ch=='k') { //knight alwsy attacks of the other color squares, so total non attacking //knighta are = half of the area //if total square is odd, i.e. dimensions are odd