当前位置: 首页>>代码示例>>C#>>正文


C# FastScanner.NextInt方法代码示例

本文整理汇总了C#中CFTraining.Helpers.FastScanner.NextInt方法的典型用法代码示例。如果您正苦于以下问题:C# FastScanner.NextInt方法的具体用法?C# FastScanner.NextInt怎么用?C# FastScanner.NextInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CFTraining.Helpers.FastScanner的用法示例。


在下文中一共展示了FastScanner.NextInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt();
         HashSet<int> set = new HashSet<int>();
         for (int i = 0; i < n; i++)
         {
             int x = fs.NextInt();
             set.Add(x);
         }
         if (set.Count < 3)
         {
             writer.WriteLine("YES");
         }
         else if (set.Count > 3)
         {
             writer.WriteLine("NO");
         }
         else
         {
             int[] a = set.ToArray();
             Array.Sort(a);
             writer.WriteLine(a[1] - a[0] == a[2] - a[1] ? "YES" : "NO");
         }
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:28,代码来源:FilyaAndHomework371.cs

示例2: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int q = fs.NextInt();
         long u, v, w;
         List<Edge> path;
         while (q-- > 0)
         {
             int t = fs.NextInt();
             if (t == 1)
             {
                 u = fs.NextLong();
                 v = fs.NextLong();
                 w = fs.NextLong();
                 path = GetPath(u, v);
                 foreach (var edge in path)
                 {
                     if (!costs.ContainsKey(edge)) costs.Add(edge, 0);
                     costs[edge] += w;
                 }
             }
             else
             {
                 u = fs.NextLong();
                 v = fs.NextLong();
                 path = GetPath(u, v);
                 writer.WriteLine(GetCost(path));
             }
         }
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:33,代码来源:LorenzoVonMatterhorn362.cs

示例3: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt(), m = fs.NextInt();
         LinkedList<int>[] adj = new LinkedList<int>[n];
         for (int i = 0; i < n; i++)
         {
             adj[i] = new LinkedList<int>();
         }
         for (int i = 0; i < m; i++)
         {
             int u = fs.NextInt() - 1, v = fs.NextInt() - 1;
             adj[u].AddLast(v);
             adj[v].AddLast(u);
         }
         bool[] visited = new bool[n];
         int ans = 0;
         for (int i = 0; i < n; i++)
         {
             if (!visited[i]) ans += DFS(i, visited, adj, -1);
         }
         writer.WriteLine(ans);
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:26,代码来源:NewReform346.cs

示例4: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt(), m = fs.NextInt();
         Player[] p = new Player[n];
         string[] ans = Enumerable.Repeat("", m).ToArray();
         for (int i = 0; i < n; i++)
         {
             string[] s = fs.ReadLine().Split();
             p[i] = new Player { Name = s[0], Region = Convert.ToInt32(s[1]) - 1, Score = Convert.ToInt32(s[2]) };
         }
         p = p.OrderBy(x => x.Region).ThenByDescending(x => x.Score).ToArray();
         int j = 0, lastRegion = -1;
         for (int i = 0; i < n; i++)
         {
             if (p[i].Region != lastRegion)
             {
                 j = 0;
                 lastRegion = p[i].Region;
             }
             if (j == 0) ans[p[i].Region] += p[i].Name + " ";
             else if (j == 1) ans[p[i].Region] += p[i].Name;
             else if (j == 2 && p[i].Score == p[i - 1].Score) ans[p[i].Region] = "?";
             j++;
         }
         for (int i = 0; i < m; i++)
         {
             writer.WriteLine(ans[i]);
         }
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:33,代码来源:QualifyingContest346.cs

示例5: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int t = fs.NextInt();
         for (int i = 1; i <= t; i++)
         {
             int n = fs.NextInt();
             int[] count = new int[(int)1e6 + 2];
             for (int j = 0; j < n; j++)
             {
                 int x = fs.NextInt() + 1;
                 count[x]++;
             }
             int ans = 0;
             for (int j = 1; j < count.Length; j++)
             {
                 if (count[j] > 0)
                 {
                     ans += (int)(Math.Ceiling(count[j]/(j * 1.0)) * j);
                 }
             }
             writer.WriteLine("Case " + i + ": " + ans);
         }
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:27,代码来源:MadCounting.cs

示例6: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int a1 = fs.NextInt(), an = fs.NextInt(), d = fs.NextInt();
         if (d == 0)
         {
             if (a1 == an) writer.WriteLine("YES");
             else writer.WriteLine("NO");
         }
         else
         {
             if ((an - a1) % d == 0)
             {
                 if ((an - a1) / d + 1 >= 1) writer.WriteLine("YES");
                 else writer.WriteLine("NO");
             }
             else
             {
                 writer.WriteLine("NO");
             }
         }
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:25,代码来源:InfiniteSequence.cs

示例7: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt();
         long[] a = new long[n], b = new long[n];
         for (int i = 0; i < n; i++)
         {
             a[i] = fs.NextInt();
         }
         for (int i = 0; i < n; i++)
         {
             b[i] = fs.NextInt();
         }
         long maxVal = a[0] + b[0];
         for (int i = 0; i < n; i++)
         {
             long aor = a[i], bor = b[i];
             maxVal = Math.Max(aor + bor, maxVal);
             for (int j = i + 1; j < n; j++)
             {
                 aor |= a[j];
                 bor |= b[j];
                 maxVal = Math.Max(aor + bor, maxVal);
             }
         }
         writer.WriteLine(maxVal);
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:30,代码来源:Interview344.cs

示例8: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt();
         long x = fs.NextInt();
         int sad = 0;
         for (int i = 0; i < n; i++)
         {
             string[] line = fs.ReadLine().Split();
             if (line[0] == "+")
             {
                 x += Convert.ToInt32(line[1]);
             }
             else
             {
                 int d = Convert.ToInt32(line[1]);
                 if (x < d) sad++;
                 else x -= d;
             }
         }
         writer.WriteLine(x + " " + sad);
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:25,代码来源:FreeIceCream359.cs

示例9: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt(), k = fs.NextInt();
         long[] c = Array.ConvertAll(fs.ReadLine().Split(), Convert.ToInt64);
         bool[] isCap = new bool[n];
         long sum = c.Sum(), res = 0, caps = 0;
         for (int i = 0; i < k; i++)
         {
             int ind = fs.NextInt() - 1;
             isCap[ind] = true;
             caps += c[ind];
         }
         for (int i = 0; i < n; i++)
         {
             int l = i - 1, r = (i + 1) % n;
             if (l < 0) l = n - 1;
             if (isCap[i]) res += c[i] * (sum - c[i]);
             else
             {
                 res += c[i] * caps;
                 if (!isCap[l]) res += c[i] * c[l];
                 if (!isCap[r]) res += c[i] * c[r];
             }
         }
         writer.WriteLine(res / 2);
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:30,代码来源:MishkaAndTrip365.cs

示例10: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt(), k = fs.NextInt();
         int[] ids = new int[n];
         for (int i = 0; i < n; i++)
         {
             ids[i] = fs.NextInt();
         }
         long sum = 0;
         long r = 0;
         for (int i = 1; i <= n; i++)
         {
             sum += i;
             if (k <= sum)
             {
                 r = i;
                 break;
             }
         }
         int index = (int)(k - (r * (r - 1)) / 2) - 1;
         writer.WriteLine(ids[index]);
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:26,代码来源:GameOfRobots350.cs

示例11: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt();
         int[] a = new int[n];
         int min = n + 1, max = 0, l = -1, r = -1;
         for (int i = 0; i < n; i++)
         {
             a[i] = fs.NextInt();
             if (a[i] < min)
             {
                 min = a[i];
                 l = i;
             }
             if (a[i] > max)
             {
                 max = a[i];
                 r = i;
             }
         }
         if (l > r)
         {
             int t = l;
             l = r;
             r = t;
         }
         if (r > n - l - 1) writer.WriteLine(r);
         else writer.WriteLine(n - l - 1);
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:32,代码来源:NikolaiAndSubstitution354.cs

示例12: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt();
         int[] a = new int[n];
         for (int i = 0; i < n; i++)
         {
             a[i] = fs.NextInt();
         }
         for (int i = 0; i < n; i++)
         {
             for (int j = 1; j < n - i; j++)
             {
                 if (a[j] < a[j - 1])
                 {
                     int t = a[j];
                     a[j] = a[j - 1];
                     a[j - 1] = t;
                     writer.WriteLine(j + " " + (j + 1));
                 }
             }
         }
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:26,代码来源:GirlsZoo359.cs

示例13: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt();
         Segment[] segms = new Segment[n];
         int[] ans = new int[n];
         for (int i = 0; i < n; i++)
         {
             segms[i] = new Segment { Id = i, Left = fs.NextInt(), Right = fs.NextInt() };
         }
         segms = segms.OrderBy(s => s.Left).ToArray();
         Segment[] t = segms.OrderBy(s => s.Right).ToArray();
         int[] ind = new int[n];
         for (int i = 0; i < n; i++)
         {
             ind[i] = findItem(t, 0, n - 1, segms[i].Right);
         }
         SegmentTree tree = new SegmentTree(new int[n]);
         for (int i = n - 1; i >= 0; i--)
         {
             ans[segms[i].Id] = tree.QuerySum(0, ind[i] - 1);
             tree.Update(ind[i], ind[i], 1);
         }
         for (int i = 0; i < n; i++)
         {
             writer.WriteLine(ans[i]);
         }
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:31,代码来源:NestedSegmentsECR10.cs

示例14: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt(), h = fs.NextInt(), k = fs.NextInt();
         int[] a = new int[n];
         for (int i = 0; i < n; i++)
         {
             a[i] = fs.NextInt();
         }
         int sum = 0, j = 0;
         long sec = 0;
         while (j < n)
         {
             while (j < n && sum + a[j] <= h) sum += a[j++];
             if (j < n)
             {
                 int need = a[j] - (h - sum);
                 int s = (int)Math.Ceiling(need * 1.0 / k);
                 sec += s;
                 sum -= s * k;
                 if (sum < 0) sum = 0;
             }
             else
             {
                 sec += (int)Math.Ceiling(sum * 1.0 / k);
             }
         }
         writer.WriteLine(sec);
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:32,代码来源:VanyaAndFoodProcessor355.cs

示例15: Run

 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt();
         int[] a = new int[n], b = new int[n];
         for (int i = 0; i < n; i++)
         {
             a[i] = fs.NextInt();
         }
         for (int i = 0; i < n; i++)
         {
             b[i] = fs.NextInt();
         }
         int l = 0, j = 0;
         int max = 0, min = 0;
         long ans = 0;
         while (j < n)
         {
             if (a[j] <= b[j])
             {
                 if (a[max] <= a[j])
                 {
                     max = j;
                     if (a[max] > b[min])
                     {
                         l = min + 1;
                         max = l;
                         min = l;
                         j = l;
                     }
                 }
                 if (b[min] >= b[j])
                 {
                     min = j;
                     if (b[min] < a[max])
                     {
                         l = max + 1;
                         min = l;
                         max = l;
                         j = l;
                     }
                 }
                 if (a[max] == b[min])
                 {
                     ans += Math.Min(max, min) + 1 - l;
                 }
             }
             else
             {
                 l = j + 1;
                 min = l;
                 max = l;
             }
             j++;
         }
         writer.WriteLine(ans);
     }
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:60,代码来源:FriendsAndSubsequences361.cs


注:本文中的CFTraining.Helpers.FastScanner.NextInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。