Advertisement
a53

cerc2

a53
Mar 8th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4. const int nmax=501;
  5. const int mmax=nmax*(nmax-3)/2;
  6. struct segm
  7. {
  8. int p1,p2,lung;
  9. };
  10. int n,j;
  11. long int m,i,p[nmax],l[nmax],ind[mmax],inters;
  12. segm per[mmax],s;
  13.  
  14. void calc(segm &s)
  15. {
  16. if(s.p2-s.p1<=n+s.p1-s.p2)
  17. s.lung=s.p2-s.p1-1;
  18. else
  19. s.lung=n+s.p1-s.p2-1,swap(s.p1,s.p2);
  20. }
  21.  
  22. void citire()
  23. {
  24. ifstream f("cerc2.in");
  25. f>>n>>m;
  26. long int i=0;
  27. while(f>>s.p1>>s.p2)
  28. {
  29. calc(s);
  30. if(s.lung==0)
  31. continue;
  32. ++p[s.p1];
  33. ++p[s.p2];
  34. ++l[s.lung];
  35. ++i;
  36. per[i]=s;
  37. }
  38. m=i;
  39. f.close();
  40. }
  41.  
  42. void sortare()
  43. {
  44. long int i,j;
  45. for(i=2;i<=n;++i)
  46. l[i]+=l[i-1];
  47. for(j=1;j<=m;++j)
  48. i=per[j].lung,ind[l[i]]=j,--l[i];
  49. }
  50.  
  51. int main()
  52. {
  53. citire();
  54. sortare();
  55. inters=0;
  56. for(i=1;i<=m;++i)
  57. {
  58. s=per[ind[i]];
  59. j=s.p1%n+1;
  60. while(j!=s.p2)
  61. {
  62. inters=(inters+p[j])%1000000;
  63. j=j%n+1;
  64. }
  65. --p[s.p1],--p[s.p2];
  66. }
  67. ofstream g("cerc2.out");
  68. g<<inters<<'\n';
  69. g.close();
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement